我在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()
。为什么会这样?