Results 1 to 12 of 12

Thread: How can i add some description about current QtreeWidgetItem inside QtreeWidgetItem

  1. #1
    Join Date
    May 2011
    Posts
    120
    Thanks
    33
    Qt products
    Qt4
    Platforms
    Windows

    Default How can i add some description about current QtreeWidgetItem inside QtreeWidgetItem

    Hai,
    I need to display some icons and information when click on current QtreeWidgetItem



    ex: code
    Qt Code:
    1. for(int i=0; i<10; i++)
    2. {
    3. QStringList strings;
    4. strings << QString("Wit Name");
    5. QTreeWidgetItem *parent = new QTreeWidgetItem(strings);
    6. ui->secTreeWidget->addTopLevelItem(parent);
    7. // Add the child TreeWidgetItem one step down in the tree
    8. parent->addChild(child);
    9. // Set the widget for the child item to be a QLineEdit for column zero.
    10. ui->secTreeWidget->setItemWidget(child, 0, new QLabel(ui->secTreeWidget));
    11. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How can i add some description about current QtreeWidgetItem inside QtreeWidgetIt

    What is the question?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    May 2011
    Posts
    120
    Thanks
    33
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How can i add some description about current QtreeWidgetItem inside QtreeWidgetIt

    When we click on an item we need to display some lines of text and symbols below the clicked item.

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How can i add some description about current QtreeWidgetItem inside QtreeWidgetIt

    I asked what is the question, and you tell me what you want to do - that is not a question, but an assertion.
    What is the problem you are having?
    What do you mean "below the clicked item"?
    Should it be part of the item?
    Should it be in the tree context?
    Do you mean like a tooltip maybe?
    If you want help, provide enough information to help you.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #5
    Join Date
    Apr 2011
    Location
    Russia
    Posts
    85
    Thanks
    2
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How can i add some description about current QtreeWidgetItem inside QtreeWidgetIt

    Qt Code:
    1. ...
    2. connect( tree, SIGNAL(clicked(QModelIndex)), this, SLOT(slotShowProp(QModelIndex)) );
    3. ...
    4. slotShowProp( QModelIndex index )
    5. {
    6. index.data( Qt::DisplayRole ); - text
    7. index.data( Qt::DecorationRole ); - icon
    8. etc..........
    9. }
    To copy to clipboard, switch view to plain text mode 

  6. The following user says thank you to Jonny174 for this useful post:

    vinayaka (2nd March 2012)

  7. #6
    Join Date
    May 2011
    Posts
    120
    Thanks
    33
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How can i add some description about current QtreeWidgetItem inside QtreeWidgetIt

    Untitled-1.jpg
    We need to display some contents (some text and symbols)below the Wit Name


    sample code is below:
    Qt Code:
    1. for(int i=0; i<3; i++)
    2. {
    3. QStringList strings;
    4. strings << QString("Wit Name");
    5. QTreeWidgetItem *parent = new QTreeWidgetItem(strings);
    6. ui->firstTreeWidget->addTopLevelItem(parent);
    7.  
    8. parent->setIcon( 0, QPixmap::fromImage( QImage("images/heart.png") ) );
    9.  
    10. // Add the child TreeWidgetItem one step down in the tree
    11. parent->addChild(child);
    12. // Set the widget for the child item to be a QLineEdit for column zero.
    13. ui->firstTreeWidget->setItemWidget(child, 0, new QLabel(ui->firstTreeWidget));
    14. }
    15. for(int i=0; i<1; i++)
    16. {
    17. QStringList strings;
    18. strings << QString("Wit Name");
    19. QTreeWidgetItem *parent = new QTreeWidgetItem(strings);
    20. ui->secTreeWidget->addTopLevelItem(parent);
    21. // Add the child TreeWidgetItem one step down in the tree
    22. parent->addChild(child);
    23. // Set the widget for the child item to be a QLineEdit for column zero.
    24. ui->secTreeWidget->setItemWidget(child, 0, new QLabel(ui->secTreeWidget));
    25. }
    26. for(int i=0; i<5; i++)
    27. {
    28. QStringList strings;
    29. strings << QString("Wit Name");
    30. QTreeWidgetItem *parent = new QTreeWidgetItem(strings);
    31. ui->thirdTreeWidget->addTopLevelItem(parent);
    32. // Add the child TreeWidgetItem one step down in the tree
    33. parent->addChild(child);
    34. // Set the widget for the child item to be a QLineEdit for column zero.
    35. ui->thirdTreeWidget->setItemWidget(child, 0, new QLabel(ui->thirdTreeWidget));
    36. }
    To copy to clipboard, switch view to plain text mode 

  8. #7
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How can i add some description about current QtreeWidgetItem inside QtreeWidgetIt

    So you want to add children to WitName - but it seems you know how to do that, based on the code you posted.
    So what is the problem?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  9. #8
    Join Date
    May 2011
    Posts
    120
    Thanks
    33
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How can i add some description about current QtreeWidgetItem inside QtreeWidgetIt

    yes.. need to add children to Wit Name,also we need to add some symbols and text below the Wit Name.The following image is our expected Ui Design.Please see the image.I expect your valuable suggestions for creating the same.
    Attached Images Attached Images
    Last edited by vinayaka; 2nd March 2012 at 13:31.

  10. #9
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How can i add some description about current QtreeWidgetItem inside QtreeWidgetIt

    Why don't you answer my questions?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  11. #10
    Join Date
    May 2011
    Posts
    120
    Thanks
    33
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How can i add some description about current QtreeWidgetItem inside QtreeWidgetIt

    Sorry..Problem is not able to add some text and Symbols below the Wit name.How can I add this?
    Its part of the current Wit Name.Its not a tool tip.

  12. #11
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How can i add some description about current QtreeWidgetItem inside QtreeWidgetIt

    I am not sure that I follow - you just add new tree (child) items - and your code is doing that already (you just are not specifying any content to the labels in the items so they are empty) ...
    Either I don't understand you, or you don't understand the code you posted - it already does what you want (as I understand you correctly), you just have to populate it with the data you want displayed.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  13. #12
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How can i add some description about current QtreeWidgetItem inside QtreeWidgetIt

    Quote Originally Posted by high_flyer View Post
    I am not sure that I follow - you just add new tree (child) items - and your code is doing that already (you just are not specifying any content to the labels in the items so they are empty) ...
    Either I don't understand you, or you don't understand the code you posted - it already does what you want (as I understand you correctly), you just have to populate it with the data you want displayed.
    I think the problem is that the OP wants to display more than just a line of text; it isn't just as simple as adding a new child item to the tree.

    @vinayaka: Look at QTreeWidget::setItemWidget(). If you create a custom widget that contains what you want (labels, text, etc.), you can then set that at the appropriate place in your tree. When that node in the tree is opened, the widget will be displayed.

    I am sure you will need to change the contents at run time, since it looks like you are trying to display dynamic contents. So also look at using QTextEdit as the item widget. You will format your text and other information (like symbols and hyperlinks) using the QTextDocument controlled by the QTextEdit.

    This will not be simple to do, but then you are asking for a UI that is not simple. And no, I cannot provide you with example code. The Qt documentation contains several tutorials and examples on how to use QTextDocument and QTextEdit.

Similar Threads

  1. Resizing a QTreeWidgetItem with a widget inside
    By NullPointer in forum Newbie
    Replies: 1
    Last Post: 16th January 2012, 02:20
  2. Replies: 5
    Last Post: 23rd September 2010, 13:58
  3. PyQt remove the current QTreeWidgetItem
    By koenux in forum Qt Programming
    Replies: 2
    Last Post: 10th January 2009, 23:08
  4. QTreeWidgetItem ?
    By allensr in forum Qt Programming
    Replies: 5
    Last Post: 3rd January 2007, 17:51
  5. QTreeWidgetItem
    By Sarma in forum Qt Programming
    Replies: 1
    Last Post: 6th April 2006, 19:52

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.