Results 1 to 3 of 3

Thread: Get the type of a QTreeWidgetItem

  1. #1
    Join Date
    Mar 2007
    Posts
    15
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Get the type of a QTreeWidgetItem

    Qt Code:
    1. void MyTreeWidget::contextMenuEvent(QContextMenuEvent* event)
    2. {
    3. QTreeWidgetItem* item = itemAt(event->pos());
    4. if (item)
    5. {
    6. // an item exists under the requested position
    7. QMenu menu(this);
    8. menu.addAction (chatAction);
    9. menu.exec(event->globalPos());
    10. }
    11. else
    12. {
    13. // there is no item under the requested position
    14. }
    15. }
    To copy to clipboard, switch view to plain text mode 

    I've subclassed QTreeWidget in order to create a context menu and what I want to do is to exclude some commands from the context menu in case an item from the tree is expandable. Like I have an item that's a group and its subitems are users and I don't want to have the option "Rename" on the user item but I want it on the group item.
    So is there like a item->isExpandable () method, or is there any way I could implement something like that? I know there's a isExpanded () method but it checks whether the item is expanded not expandable.

    I've checked here and didn't find anything useful.

    I hope I made my question clear enough.

    Thanks.

  2. #2
    Join Date
    Mar 2007
    Posts
    15
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Get the type of a QTreeWidgetItem

    Just found out, sorry for the useless topic :|

    Qt Code:
    1. void MyTreeWidget::contextMenuEvent(QContextMenuEvent* event)
    2. {
    3. QTreeWidgetItem* item = itemAt(event->pos());
    4. if (item)
    5. {
    6. // an item exists under the requested position
    7. if (item->parent ()) /* or if (!item->childCount())*/
    8. {
    9. // the item is not expandable
    10. QMenu menu(this);
    11. menu.addAction (chatAction);
    12. menu.exec(event->globalPos());
    13. }
    14. }
    15. else
    16. {
    17. // there is no item under the requested position
    18. }
    19. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Get the type of a QTreeWidgetItem

    Item is expandable if it has children, so all you need to do is to check the child count.

Similar Threads

  1. Installation on Fedora Core 4
    By jcr in forum Installation and Deployment
    Replies: 3
    Last Post: 29th January 2009, 01:34
  2. How to dinamically change the type of a QCheckListItem
    By kalos80 in forum Qt Programming
    Replies: 4
    Last Post: 12th March 2007, 15:25
  3. QTreeWidgetItem ?
    By allensr in forum Qt Programming
    Replies: 5
    Last Post: 3rd January 2007, 17:51
  4. what is type?
    By gfunk in forum Qt Programming
    Replies: 4
    Last Post: 12th August 2006, 17:40
  5. Problems
    By euthymos in forum Installation and Deployment
    Replies: 2
    Last Post: 13th June 2006, 19:11

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.