double clicked on an item QTreeWidget
I am using QTreeWidget on the MainWindow and items are added to the TreeWidget from a table of a database.The tree has four rows and two columns.When i double click either the root or children on the specific row of the tree,then displays another widget.I am doing this using QModelIndex object.I want only the root of the row to "goes to" the specified widget and not the children.
My code is:
//Double click on the treeWidget
void MainWindow::changeSWidget(QModelIndex index)
{
//row 0
case Tree::Computers://1
ui->stackedWidget->setCurrentWidget(comp);
break;
case Tree::Files://1
ui->stackedWidget->setCurrentWidget(file);
break;
}
connect(Tree,SIGNAL(loadWidget(QModelIndex)),this, SLOT(changeSWidget(QModelIndex)));
How can i find which item is clicked ??Doing this when i clicked on each item is called the slot display.
//double click on treewidget items
connect(ui->treeWidget,SIGNAL(itemDoubleClicked(QTreeWidgetIt em*,int)),this,SLOT(display(QTreeWidgetItem*,int)) );
Is it better for me to use a model/view approach??
i hope you understand what i am saying..
Re: double clicked on an item QTreeWidget
Quote:
How can i find which item is clicked ??
you can do this by checking the text of the item clicked :
Code:
{
if(index.data().toString()=="TableRecipts")
createTableReciptsModel();
}
or, if you have more than row with the same text , you can check both the text and the index :
Code:
else if(customersTreeValue=="totalBounty"&&index.row()==0)
{
totalBountyClicked();
}
i hope i was helpful .
Re: double clicked on an item QTreeWidget
your answer helps me to understand how can i do what i wanted...In the treeWidget are stored primary keys of a table and with this piece of code i get the content of the column:
index.sibling(index.row(),2).data().toInt()
Thanks a lot again
Re: double clicked on an item QTreeWidget
u r welcome
i am glad that you solved the problem :)