Hello.
How can I insert QLabel(as item) to QListWidget (or QListView)? I want this for adding rich text messages to list widget.
Can anyone please post some examples?
Printable View
Hello.
How can I insert QLabel(as item) to QListWidget (or QListView)? I want this for adding rich text messages to list widget.
Can anyone please post some examples?
Oh, that's a bad idea because of performance reasons. A much better one is to implement a custom delegate that would render rich text using QTextDocument. I think there's even an example of such a delegate on the forum somewhere.
You are thinking about this: http://www.qtcentre.org/forum/f-qt-p...view-8371.html?
Post #19 in the thread looks promising, although I was referring to some other thread. You can also download my wwWidgets and look at the QwwRichTextButton implementation and implement a similar thing as a delegate.
For first I must explain something.
I would like to do the chat widget.
So I started with the QTextBrowser.
After adding 80 lines(every line contained 30 pictures(16x16px gif)), the QTextBrowser turned out to be too slow(slow selecting text, slow srolling, etc.).
So perhaps would the QListWidget(with rich text items) be good for chat presentation?
OK. I downloaded http://www.qtcentre.org/forum/attach...3&d=1188673979.
I changed in maindialog.cpp lines:
to:Code:
<< "The <b>QListWidgetItem</b> class provides an item for use with the QListWidget item view class. The <b>QListWidgetItem</b> class provides an item for use with the QListWidget item view class. The <b>QListWidgetItem</b> class provides an item for use with the QListWidget item view class." << "The <b>QObject</b> class is the base class of all Qt objects." << "Qt's <b>drag and drop</b> infrastructure is fully supported by the model/view framework. Items in lists, tables, and trees can be dragged within the views, and data can be imported and exported as MIME-encoded data.";
Result is wrong, because the text "The QListWidgetItem class." is covering the different text(See attachment.)Code:
<< "<font size=\"6\">The <b>QListWidgetItem</b> class." << "The <b>QObject</b> class is the base class of all Qt objects." << "Qt's <b>drag and drop</b>";
In sectionitem.cpp I changed in function:
one line:Code:
{ float rw = float(p->viewport()->size().width()); float tw = fm.width(itemText); float ratio = tw/rw; int lines = int(ratio) + 1; }
That works fine, but only when I don't resize widget and when text is "<font size=\"6\">The <b>QListWidgetItem</b> class.".Code:
int lines = int(ratio) + 2;
How to calculate the number of lines dynamically, if the text have different lenght and font sizes?
Can anyone help?
The text document can calculate the size of its contents, so just use it.