1

我在 Windows 7 Ultimate 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_buttonpoint_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()鼠标左键点击不会被调用。为什么会这样?

4

0 回答 0