【发布时间】:2019-06-06 10:00:13
【问题描述】:
我已经用 QAbstractItemModel 实现了一个 QTreeview,如果我用鼠标左键单击树视图项目,我如何得到通知。我们是否有任何类似 OnLButtonDown() 的函数可用于树视图。
WavefrontRenderer::WavefrontRenderer(TreeModel* model , QWidget *parent) :
QMainWindow(parent)
{
setupUi(this);
treeView->setModel(model);
treeView->setDragEnabled(true);
treeView->setAcceptDrops(true);
treeView->installEventFilter(this);
connect(pushButtonAddGroup, SIGNAL(clicked()), this, SLOT(insertRow()));
connect(pushButtonAddChild , SIGNAL(clicked()), this,
SLOT(insertChild()));
connect(pushButtonDeleteGroup , SIGNAL(clicked()), this,
SLOT(removeRow()));
connect( ButtonSphere, SIGNAL(clicked()), this, SLOT(AddSphere()));
connect(treeView , SIGNAL(clicked()), this, SLOT(message()));
}
我尝试将树视图连接到单击的插槽,但这对我不起作用。
由于我是 qt 的新手,我不确定我们连接树视图的方式是否与将按钮连接到单击的插槽的方式相同。
【问题讨论】:
-
你有
clicked信号。 -
如何将它连接到树视图?
-
我试过 connect(treeView , SIGNAL(clicked()), this, SLOT(message()));
-
对我不起作用。
-
请编辑您的问题以显示您迄今为止尝试过的代码,并更清楚地解释您想要实现的目标。