QToolbar在第二次调用show/setVisible之前不可见(true)
我面临着某种神秘感:QToolbar在第二次调用show/setVisible之前不可见(true),qt,qtoolbar,Qt,Qtoolbar,我面临着某种神秘感: if( itemSelectionne->parentItem()->type() == NodeType) { ((GraphicsScene*) this->scene())->unselectAll(); itemSelectionne->parentItem()->setSelected(true); //Coordinate of my toolbar, works fine int ce
if( itemSelectionne->parentItem()->type() == NodeType) {
((GraphicsScene*) this->scene())->unselectAll();
itemSelectionne->parentItem()->setSelected(true);
//Coordinate of my toolbar, works fine
int centreX = itemSelectionne->pos().x() +
itemSelectionne->boundingRect().center().x();
int centreY = itemSelectionne->pos().y() +
itemSelectionne->boundingRect().center().y();
QPointF point = this->mapFromScene(
itemSelectionne->mapToScene(QPoint(centreX, centreY))
);
_nm.move(point.x(), point.y());
_nm.show((GraphicsNodeItem*) itemSelectionne->parentItem());
}
在QGraphicsView上单击鼠标后,我输入这段代码以显示我的QToolbar(_nm是一个包含2个QToolbar的自定义对象。show(…)调用QToolbar上的show()
第一次输入if和call show()时,QToolbar不会显示。但它会在第二次单击时显示,之后每隔一次单击都会显示
知道它是从哪里来的吗
Thx
编辑:这是我在自定义类中调用的函数_currentNode是指向自定义QGraphicsSiteMgroup子类的指针
void NodeMenu::show(GraphicsNodeItem * node) {
_currentNode = node;
_menuTop.show();
_menuBottom.show();
}
找到了一个解决方案:
我在自定义对象的构造函数中添加了以下内容:
_menuTop.show();
_menuBottom.show();
我不知道这是否是一个好的解决方案,但它对我有效 我不认为QWidget::show()接受任何参数。。。那一行到底应该做什么?对,那是因为show调用了我的类中包含的2个QToolbar对象(_nm是由2个QToolbar组成的)。您是否验证了在第一次单击时调用了“show”函数?