Results 1 to 5 of 5

Thread: QTreeWidget questions

  1. #1
    Join Date
    Feb 2006
    Posts
    27
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default QTreeWidget questions

    Question one:
    I have a QTreeWidget with items and I want to grab the collapsed/expanded but it returns a QModelIndex. So how do I grab a collapse or expand that will give me back a QTreeWidgetItem? All the post I've read about this never really answered the question!

    Question two:
    How do you remove the column at the top? I only have one column and I don't like seeing the 0 at the top of the column. I've searched the doc's but might be missing it or it might be something done in QTDesigner.

    Question three:
    The following code was how I was thinking of changing the icon from open to close an image is there a better way?
    Qt Code:
    1. p_tree_widget->setColumnCount(1);
    2. connect(p_tree_widget, SIGNAL(collapsed(QModelIndex &)), this, SLOT(collapsed(QModelIndex &)));
    3. connect(p_tree_widget, SIGNAL(expanded (QModelIndex &)), this, SLOT(expanded (QModelIndex &)));
    4. QTreeWidgetItem *p_folder = new QTreeWidgetItem(project_tree);
    5. p_folder->setText(0, tr("Content"));
    6. p_folder->setIcon(0, QIcon(":/images/closed_folder.png"));
    7. QTreeWidgetItem *p_data = new QTreeWidgetItem(project_tree);
    8. p_data->setText(0, tr("data"));
    9. p_data->setIcon(0, QIcon(":/images/data.png"));
    10.  
    11. void collapsed ( const QModelIndex &index )
    12. {
    13. // get QTreeWidgetItem
    14. p_collapsed->setIcon(0, QIcon(":/images/closed_folder.png"));
    15. };
    16. void expanded ( const QModelIndex &index )
    17. {
    18. // get QTreeWidgetItem
    19. p_collapsed->setIcon(0, QIcon(":/images/open_folder.png"));
    20. };
    To copy to clipboard, switch view to plain text mode 

    Thanks for any help that you may give me!

  2. #2
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeWidget questions

    Question one:
    I have a QTreeWidget with items and I want to grab the collapsed/expanded but it returns a QModelIndex. So how do I grab a collapse or expand that will give me back a QTreeWidgetItem? All the post I've read about this never really answered the question!
    connect itemExpanded and itemCollapsed signal to your slots

    Question two:
    How do you remove the column at the top? I only have one column and I don't like seeing the 0 at the top of the column. I've searched the doc's but might be missing it or it might be something done in QTDesigner.
    use setItemHidden(headerItem(),true);

  3. The following user says thank you to munna for this useful post:

    fellobo (2nd May 2006)

  4. #3
    Join Date
    Feb 2006
    Posts
    27
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTreeWidget questions

    The QTreeWidget doesn't have a signal collapsed or expanded. I thought I read that within the QT documenation http://doc.trolltech.com/4.1/qtreewi...l#itemExpanded is the better way to go....

  5. #4
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeWidget questions

    void QTreeWidget::itemExpanded ( QTreeWidgetItem * item ) [signal]

    This signal is emitted when the specified item is expanded so that all of its children are displayed.

    See also setItemExpanded() and isItemExpanded().

    This is what the documentation says. So using this signal you can know that an item is expanded and also the item which is getting expnaded. Same applies for itemCollapsed.

  6. #5
    Join Date
    Feb 2006
    Posts
    27
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTreeWidget questions

    Thanks munna,
    I must have been in the QTreeView (browsing back that is where I was although I don't know why.)

    I found the correct documentation and now have it working.... Thanks for the help

Similar Threads

  1. how to sync a QTreeWidget and a QListWidget?
    By zl2k in forum Qt Programming
    Replies: 2
    Last Post: 5th September 2008, 20:55
  2. QTreeWidget Drag and Drop
    By tommydent in forum Qt Programming
    Replies: 10
    Last Post: 25th August 2008, 15:25
  3. QTreeWidget nextSibling()
    By user_mail07 in forum Newbie
    Replies: 1
    Last Post: 21st August 2008, 19:44
  4. resizing a QTreeWidget
    By drhex in forum Qt Programming
    Replies: 6
    Last Post: 27th October 2006, 22:32
  5. few questions related to QTreeWidget
    By prakash in forum Qt Programming
    Replies: 9
    Last Post: 10th March 2006, 07:32

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.