Results 1 to 5 of 5

Thread: Displaying richtext on ItemWidgets

  1. #1
    Join Date
    Aug 2008
    Posts
    27
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Displaying richtext on ItemWidgets

    The easiest way is to search the forum for similar issues.

  3. #3
    Join Date
    Aug 2008
    Posts
    27
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question 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...

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Displaying richtext on ItemWidgets

    You can still you QTextDocument through its text layout, as far as I remember.

  5. #5
    Join Date
    Aug 2008
    Posts
    27
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Displaying richtext on ItemWidgets

    ok.

    i finally found one of your early posts on this topic which gives a sample code

    Qt Code:
    1. void CommentDelegate::paint( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const
    2. {
    3. painter->save();
    4. doc.setHtml( index.data().toString() );
    5. QAbstractTextDocumentLayout::PaintContext context;
    6. doc.setPageSize( option.rect.size());
    7. painter->translate(option.rect.x(), option.rect.y());
    8. doc.documentLayout()->draw(painter, context);
    9. painter->restore();
    10. }
    To copy to clipboard, switch view to plain text mode 

    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:ageSize() and QTextDocument::documentLayout()->documentSize() methods , after setting the content of the QTextDocument object , but it didnt worked.

    any suggestions appreciated.. thanks...

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.