Results 1 to 4 of 4

Thread: QTreeWidget Help pls

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

    Default QTreeWidget Help pls

    Hi,

    I am inserting QTreeWidgetItem in QTreeWidget using addTopLevelItem() and also making it editable by setting appropriate flag.

    How can i directly insert an Item in edit mode ?

    Is there a way by which i can know that an item an gone from editmode to select mode and vice-versa?

    Thanks

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QTreeWidget Help pls

    So you want the item in edit mode right after adding it to the tree?
    There is a method for starting the edit mode: QTreeWidget::editItem().

    Qt Code:
    1. QTreeWidgetItem* item = new QTreeWidgetItem(tree);
    2. // need to add editable flag, items are not editable by default
    3. item->setFlags(item->flags() | Qt::ItemIsEditable);
    4. tree->editItem(item, 0);
    To copy to clipboard, switch view to plain text mode 

  3. #3
    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 Help pls

    Thanks for replying.

    Is there a way by which i can know that an item has become editable or has changed from editable to non-editable (Basically is there a way by which i can know if the user is done with his editing?)

    Thanks a lot

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QTreeWidget Help pls

    Hrm, I couldn't find any neat way to do that.

    One way I found:
    Qt Code:
    1. class Something ...
    2. {
    3. ...
    4. private slots:
    5. void setEditItem(QTreeWidgetItem* item);
    6. void itemEditDone();
    7. private:
    8. QTreeWidget* m_tree;
    9. QTreeWidgetItem* m_item;
    10. ...
    11. };
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. connect(m_tree, SIGNAL(itemChanged(QTreeWidgetItem*, int)),
    2. this, SLOT(setEditItem(QTreeWidgetItem*)));
    3. connect(m_tree->itemDelegate(), SIGNAL(closeEditor(QWidget*, QAbstractItemDelegate::EndEditHint)),
    4. this, SLOT(itemEditDone()));
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void Something::setEditItem(QTreeWidgetItem* item)
    2. {
    3. // keep track of the changing item
    4. // this gets called when items are eg. added, not only when edited...
    5. m_item = item;
    6. }
    7.  
    8. void Something::itemEditDone()
    9. {
    10. // this gets called when the actual editing is done
    11. // currentItem() does not workie here so that's why
    12. // keeping track of changing items :p
    13. qDebug() << m_item->text(0);
    14. }
    To copy to clipboard, switch view to plain text mode 

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. Having trouble clearing a QTreeWidget.
    By Nyphel in forum Qt Programming
    Replies: 28
    Last Post: 10th October 2007, 15:33
  4. how to add icons to QTreeWidget?
    By wei243 in forum Qt Programming
    Replies: 4
    Last Post: 21st September 2007, 08:34
  5. resizing a QTreeWidget
    By drhex in forum Qt Programming
    Replies: 6
    Last Post: 27th October 2006, 22: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.