Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
QToolbar在第二次调用show/setVisible之前不可见(true)_Qt_Qtoolbar - Fatal编程技术网

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”函数?