After you create your QTreeWidgetItem you need to add it to a selectable QTreeWidget
...
mTreeWidget->addTopLevelItem(cities);
mTreeWidget->setSelectionMode(QAbstractItemView::MultiSelection);
...
mTreeWidget->addTopLevelItem(cities);
To copy to clipboard, switch view to plain text mode
Whenever any item in the tree is selected the tree emits an itemClicked signal which you connect to like
{
//Do whatever you want to the item here
}
QObject::connect(mTreeWidget, SIGNAL(itemClicked(QTreeWidgetItem*, int)), this, SLOT(onClicked(QTreeWidgetItem*, int)));
onClicked(QTreeWidgetItem* item, int column)
{
//Do whatever you want to the item here
}
To copy to clipboard, switch view to plain text mode
You actually shouldn't need to set you objects checked state manually the tree will do that automatically
Bookmarks