鼠标事件不会传递给QGraphicsItemGroup中添加的QPushButton

时间:2012-09-23 18:09:15

标签: c++ qt

我在Windows 7旗舰版x64上使用Qt 4.8.3(32位)。

QGraphicsScene子类的构造函数中,我有:

QGraphicsItemGroup *point_table = new QGraphicsItemGroup;
addItem(point_table);

稍后在构造函数中:

QPushButton *button = new QPushButton("Call++");
QGraphicsProxyWidget *inc_button = addWidget(button);
connect(button, SIGNAL(clicked()), this, SLOT(onCallIncrease()));
单击按钮时会调用

onCallIncrease()。但是,如果我将inc_button添加到point_table,则onCallIncrease()不会被调用。

QPushButton *button = new QPushButton("Call++");
QGraphicsProxyWidget *inc_button = addWidget(button);
point_table->addToGroup(inc_button);
connect(button, SIGNAL(clicked()), this, SLOT(onCallIncrease())); // doesn't work

即使我手动设置为接受鼠标左键:

QPushButton *button = new QPushButton("Call++");
QGraphicsProxyWidget *inc_button = addWidget(button);
inc_button->setAcceptedMouseButtons(Qt::LeftButton);
point_table->setAcceptedMouseButtons(Qt::LeftButton);
point_table->addToGroup(inc_button);
connect(button, SIGNAL(clicked()), this, SLOT(onCallIncrease())); // doesn't work
单击鼠标左键不会调用

onCallIncrease()。为什么会这样?

0 个答案:

没有答案