
Originally Posted by
jpn
Perhaps you could even use the built-in signal
QTreeWidget::itemClicked(QTreeWidget* item, int column) and simply cast the passed item:
void Receiver
::doSomething(QTreeWidget* item,
int column
) {
MyTreeWidgetItem* myItem = dynamic_cast<MyTreeWidgetItem*>(item);
if (myItem)
{
// yes, it's a "MyTreeWidgetItem", do something with it's "element"
}
}
connect(treeWidget, SIGNAL(itemClicked(QTreeWidget*, int)), receiver, SLOT(doSomething(QTreeWidget*, int)));
void Receiver::doSomething(QTreeWidget* item, int column)
{
MyTreeWidgetItem* myItem = dynamic_cast<MyTreeWidgetItem*>(item);
if (myItem)
{
// yes, it's a "MyTreeWidgetItem", do something with it's "element"
}
}
To copy to clipboard, switch view to plain text mode
Actually you could store the element information as QTreeWidgetItem's user data, without the need of subclassing QTreeWidgetItem.
I did what you said,
{
}
QObject::connect(ui.treeWidget, SIGNAL(itemClicked(QTreeWidgetItem*, int)), this, SLOT(testslot(QTreeWidgetItem*, int)));
void test::testslot(QTreeWidgetItem* item, int column)
{
QString str = item->text(column);
QMessageBox::information(0, "testslot", str, QMessageBox::Ok);
}
To copy to clipboard, switch view to plain text mode
The strange thing is that the message box appears many times when I click on any item. 22 times on my laptop and 38 or 39 times on my workstation...
Bookmarks