在第二次调用show / setVisible之前看不到QToolbar(true)

时间:2012-04-21 17:20:00

标签: qt qtoolbar

我正面临某种神秘感:

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的自定义对象。显示(...)调用QToolbar上的show()) 我第一次进入if和调用show()时QToolbar没有显示出来。但它出现在第二次点击和之后的每次其他点击。

知道它可能来自哪里?

THX

编辑:这是我在自定义类中调用的函数。 _currentNode是指向自定义QGraphicsItemGroup子类的指针。

void NodeMenu::show(GraphicsNodeItem * node) {
_currentNode = node;

_menuTop.show();
_menuBottom.show();
}

1 个答案:

答案 0 :(得分:0)

找到解决方案:

我在自定义对象的构造函数中添加了以下内容:

_menuTop.show();
_menuBottom.show();

我不知道这是否是一个很好的解决方案,但它对我有用。

相关问题