PDA

View Full Version : Getting currentIndex from Selected item in QtreeWidget



nbkhwjm
26th January 2008, 04:52
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...




connect(ui.treeWidget, SIGNAL(itemClicked(QTreeWidgetItem*,int)),
this, SLOT(setActiveTool());


int Porcupine::setActiveTool()
{

// What goes here to determine the current index of the selected tree item?

switch (item) {
case 0:
{
ui.pageTitle->setText("case 0");
}
break;

case 1:
{
ui.pageTitle->setText("case 1");
}
break;

case 2:
{
ui.pageTitle->setText("case 2");
}
break;
}
}

munna
26th January 2008, 05:25
How about using indexOfTopLevelItem to get the index ?

wysota
26th January 2008, 10:20
The signal carries a pointer to the item. Make your slot accept it as an argument and use it.