Displaying richtext on ItemWidgets
Hi,
i am new at QT and just started to read Qt examples and tutorials.
i want to display richtext formatted by using HTML-tags ,like QLabel does, in the qt item widgets ( i.e QListWidget,QTableWidget etc. ). I don't know what should my starting point. Defining a custom delegate or inheriting Item classes. Or do i have to use item views instead?
what is the easiest way for that?
Re: Displaying richtext on ItemWidgets
The easiest way is to search the forum for similar issues.
Re: Displaying richtext on ItemWidgets
i have found some similar issue to my question at the forum thread :
http://www.qtcentre.org/forum/f-qt-p...thod-8660.html
there , QTextDocument is been mentioned as the solution to render rich text
on the paint() method of custom Delegate.
QTextDocument::drawContents() is introduced by Qt 4.2
İ am using Qt. Coomercial 4.1.3.
arent there any "Qt. 4.1.3 before" solution for rendering RichText on paint().?
BTW; i keep searching on this both at forum and swhr else. no need to remind that
thanks...
Re: Displaying richtext on ItemWidgets
You can still you QTextDocument through its text layout, as far as I remember.
Re: Displaying richtext on ItemWidgets
ok.
i finally found one of your early posts on this topic which gives a sample code
Code:
{
painter->save();
doc.setHtml( index.data().toString() );
doc.setPageSize( option.rect.size());
painter->translate(option.rect.x(), option.rect.y());
doc.documentLayout()->draw(painter, context);
painter->restore();
}
i used this method and it worked. But now there is another problem of obtaining
right size values to be returned from sizeHint() function.
i am reimplementing the sizeHint() method of the Delegate and for the time being, i am just returning a constant size of QSize(200,250). But of course this should be determined by the content of the item to be displayed. For large contents; some of the text are just lost behind the content of next item.
i tried QTextDocument::pageSize() and QTextDocument::documentLayout()->documentSize() methods , after setting the content of the QTextDocument object , but it didnt worked.
any suggestions appreciated.. thanks...