treewidget

How can I find the selected item in a QTreeWidget?

自闭症网瘾萝莉.ら 提交于 2019-12-09 13:15:43
问题 I have a class that inherits QTreeWidget. How can I find the currently selected row? Usually I connect signals to slots this way: connect(myButton, SIGNAL(triggered(bool)), this, SLOT(myClick())); However, I can't find anything similar for QTreeWidget->QTreeWidgetItem . The only way I found is to redefine the mousePressEvent of the QTreeWidget class like this: void MyQTreeWidget::mousePressEvent(QMouseEvent *e){ QTreeView::mousePressEvent(e); const QModelIndex index = indexAt(e->pos()); if (

How can I find the selected item in a QTreeWidget?

陌路散爱 提交于 2019-12-03 15:22:56
I have a class that inherits QTreeWidget. How can I find the currently selected row? Usually I connect signals to slots this way: connect(myButton, SIGNAL(triggered(bool)), this, SLOT(myClick())); However, I can't find anything similar for QTreeWidget->QTreeWidgetItem . The only way I found is to redefine the mousePressEvent of the QTreeWidget class like this: void MyQTreeWidget::mousePressEvent(QMouseEvent *e){ QTreeView::mousePressEvent(e); const QModelIndex index = indexAt(e->pos()); if (!index.isValid()) { const Qt::KeyboardModifiers modifiers = QApplication::keyboardModifiers(); if (!