Results 1 to 3 of 3

Thread: Getting currentIndex from Selected item in QtreeWidget

  1. #1
    Join Date
    Mar 2007
    Posts
    59
    Thanks
    7

    Default Getting currentIndex from Selected item in QtreeWidget

    I have a QtreeWidget build with designer with three items.

    I want to execute a function when each item is selected, i can connect the signal itemclicked to a function, then what can i use to do a switch case?

    Ive tried qtreewidgetitem, but no luck...

    I setup the Signal/slot so that is calls a function...

    Qt Code:
    1. connect(ui.treeWidget, SIGNAL(itemClicked(QTreeWidgetItem*,int)),
    2. this, SLOT(setActiveTool());
    3.  
    4.  
    5. int Porcupine::setActiveTool()
    6. {
    7.  
    8. // What goes here to determine the current index of the selected tree item?
    9.  
    10. switch (item) {
    11. case 0:
    12. {
    13. ui.pageTitle->setText("case 0");
    14. }
    15. break;
    16.  
    17. case 1:
    18. {
    19. ui.pageTitle->setText("case 1");
    20. }
    21. break;
    22.  
    23. case 2:
    24. {
    25. ui.pageTitle->setText("case 2");
    26. }
    27. break;
    28. }
    29. }
    To copy to clipboard, switch view to plain text mode 

  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: Getting currentIndex from Selected item in QtreeWidget

    How about using indexOfTopLevelItem to get the index ?

  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: Getting currentIndex from Selected item in QtreeWidget

    The signal carries a pointer to the item. Make your slot accept it as an argument and use it.

Similar Threads

  1. How to know wich item is clicked QTreeWidget
    By ^NyAw^ in forum Qt Programming
    Replies: 13
    Last Post: 6th November 2007, 23:47
  2. Changing selected item color in non-current window.
    By Doug Broadwell in forum Qt Programming
    Replies: 1
    Last Post: 26th August 2007, 07:09
  3. QTreeView: selection behavior upon selected item removal
    By Pieter from Belgium in forum Qt Programming
    Replies: 6
    Last Post: 11th July 2007, 16:00
  4. Inserting Item to a QTreeWidget from Thread?
    By vishal.chauhan in forum Qt Programming
    Replies: 3
    Last Post: 23rd June 2007, 11:23
  5. Removing items properly from qtreewidget item
    By Djony in forum Qt Programming
    Replies: 6
    Last Post: 21st November 2006, 12:20

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.