Bug with the first default position of a QMenu in a QGraphicsScene

  • Hi,
    I think this issue is related to this old bug: https://bugreports.qt.io/browse/QTBUG-47114

    I'm having a QGraphicsScene where I'm adding Widgets using

    QGraphicsProxyWidget *QGraphicsScene::addWidget(QWidget *widget, Qt::WindowFlags wFlags = ...)

    My Widget has a QToolButton that is opening a QMenu:

    ComboTreeBox::ComboTreeBox(): QToolButton(parent),
        _popupMenu(new QMenu("Popup_ComboTreeBox", this))
        QWidgetAction *action = new QWidgetAction(this);
        connect(_popupMenu, &QMenu::aboutToShow, _navigator, &DataNavigator::clearSearchField);

    So as explained in the documentation of QGraphicsProxyWidget

    QGraphicsProxyWidget takes care of automatically embedding popup children of embedded widgets through creating a child proxy for each popup. This means that when an embedded QComboBox shows its popup list, a new QGraphicsProxyWidget is created automatically, embedding the popup, and positioning it correctly. This only works if the popup is child of the embedded widget (for example QToolButton::setMenu() requires the QMenu instance to be child of the QToolButton).

    My QMenu is a child (grand child actually) of the widget I'm inserting in the Scene.

    The first time I click on the ToolButton, the position of the QMenu is wrong, is appears on the top left quite far of my button. This give a bad user experience as the GraphicsView is getting bigger and thus the scrollbars appears plus the scene is moving a little.

    After the first time the Menu is well displayed under my button.
    Any idea what I could do to avoid this bug of first appearance?

    what solution could I have?
    Maybe not using Menus but directly a widget that I'll manually insert/remove in the desired position with a zOrder bigger than my normal items?

  • Any update on this issue?
    I'll try to make a mini example of my use case when I've some free time.
    It is quite an annoying user experience...

Log in to reply