Results 1 to 8 of 8

Thread: QTreeWidget::setItemWidget ( QTreeWidgetItem * item, int column, QWidget * widget )

  1. #1
    Join Date
    Jan 2007
    Posts
    326
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default QTreeWidget::setItemWidget ( QTreeWidgetItem * item, int column, QWidget * widget )

    Hi

    Working on Qt4.4 on my mac machine,

    I used QLabel to display text in QTreeWidget by using setItemWidget, It works fine, but when I scroll QTreeWidget up or down, the item in the QLabel will disappear. What can I do when I scroll QTreeWidget up or down the item in the label will not dissapear.

    Thanks
    Always Believe in Urself
    Merry

  2. #2
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTreeWidget::setItemWidget ( QTreeWidgetItem * item, int column, QWidget * widget

    First of all - why are you using QLabel to display text in QTreeWidget? Is there any special functionality of QLabel, which you need in your case? Did you try it in "normal" way without any widgets in view?
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  3. #3
    Join Date
    Jan 2007
    Posts
    326
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: QTreeWidget::setItemWidget ( QTreeWidgetItem * item, int column, QWidget * widget

    I want to use formatted string - that is the string with two different fonts, thats why I used label, in which i will be able to display html text.

    In normal way, without any widgets it is working fine.

    But I have to use label.
    Always Believe in Urself
    Merry

  4. #4
    Join Date
    Jan 2007
    Posts
    326
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: QTreeWidget::setItemWidget ( QTreeWidgetItem * item, int column, QWidget * widget

    Pls reply is there any way , that on scrolling up down the treeWidget , QWidget will not dissappear.
    Always Believe in Urself
    Merry

  5. #5
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTreeWidget::setItemWidget ( QTreeWidgetItem * item, int column, QWidget * widget

    Using widgets in views is not recommended as it is slow and resource consuming, and views are not for widgets (layouts are). But sometimes widget functionality is needed in view, but in such simple case as yours (displaying rich text via QLabel) it is bad idea to you QLabel. I would suggest you implementing a delegate which draws your text in your own way. You can use QTextDocument in your case and it shouldn't be complicated.
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  6. #6
    Join Date
    Jan 2007
    Posts
    326
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: QTreeWidget::setItemWidget ( QTreeWidgetItem * item, int column, QWidget * widget

    Thanks for the reply.

    I tried to use QTextDocument parent QTextEdit, and by using this also on Scrolling treeWidget up down i still got the same problem.

    Is there any other way that i can use html string in QTreeWidgetItem.

    So that I can add that formatted text in QTreeWidgetItem.
    Always Believe in Urself
    Merry

  7. #7
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QTreeWidget::setItemWidget ( QTreeWidgetItem * item, int column, QWidget * widget

    can you provide a minimal compilable program reproducing your problem?

  8. #8
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTreeWidget::setItemWidget ( QTreeWidgetItem * item, int column, QWidget * widget

    Quote Originally Posted by merry View Post
    Is there any other way that i can use html string in QTreeWidgetItem.
    I already told you - create your own delegate, which will paint the formatted text. And for painting you can use QTextDocument. It has its nice method QTextDocument::drawContents().
    I tried to use QTextDocument parent QTextEdit
    you don't need any QTextEdit there.

    EDIT:
    It is not that hard. The example which is shown below took 60 lines of code, where main() is almost half of it and is just adding items :P
    Attached Images Attached Images
    Last edited by faldzip; 19th October 2010 at 10:30. Reason: updated contents
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

Similar Threads

  1. Replies: 1
    Last Post: 7th July 2010, 09:00
  2. Replies: 2
    Last Post: 24th May 2009, 11:27
  3. Replies: 1
    Last Post: 18th November 2008, 07:57
  4. QTreeWidget item editing: want column specificity
    By McKee in forum Qt Programming
    Replies: 12
    Last Post: 10th December 2006, 23:12
  5. Replies: 1
    Last Post: 21st September 2006, 11:37

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.