Results 1 to 2 of 2

Thread: sizeHint based off visible text

  1. #1
    Join Date
    Aug 2008
    Location
    Iowa, USA
    Posts
    21
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default sizeHint based off visible text

    I've searched the forums for sizeHint, but I have been unable to find out to figure out a good sizeHint based off the visible text when displaying html. Currently the sizeHint works wonderfully for all the text in the cell (I just see how many characters are in the QTextDocument), but not so good for just giving a good sizeHint for the characters my user will actually see. Can someone point me in the right direction?

  2. #2
    Join Date
    Aug 2008
    Location
    Iowa, USA
    Posts
    21
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: sizeHint based off visible text

    I've found a solution that works. Here is the code
    Qt Code:
    1. if (qVariantCanConvert<QString>( index.data() ) ) {
    2. QString htmlText = qVariantValue<QString>(index.data());
    3. qtd.setHtml(htmlText);
    4. qtd.setTextWidth(-1);
    5. QSize toRet;
    6. toRet.setWidth( ceil( qtd.idealWidth() ) );
    7. toRet.setHeight( ceil( qtd.size().height() ) );
    8. return toRet;
    9. } else {
    10. return QItemDelegate::sizeHint(option, index);
    11. }
    To copy to clipboard, switch view to plain text mode 
    I'm sure there might be a better way, but this seems to work. The QTextDocument gives back a QSizeF, which means it might round down when it should be rounding up all the time. If someone knows of a better way to do this, I'm all ears.

Similar Threads

  1. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 10:49
  2. QLabel - visible text function or something else
    By john in forum Qt Programming
    Replies: 3
    Last Post: 20th April 2008, 12:26
  3. Text in QTableView cells not visible
    By juliarg in forum Newbie
    Replies: 2
    Last Post: 22nd March 2007, 16:49
  4. visible text of textedit
    By regix in forum Qt Programming
    Replies: 3
    Last Post: 26th June 2006, 10:02

Tags for this Thread

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.