Paint order of QWidgetAction added to QMenu changes if QMenu called from context menu?

  • Hi,
    I have added a QCombobox to a QWidgetAction which is added to a QMenu called m_rangeMenu.

    This m_rangeMenu created in a child plot widget, and requested by the Main app. which adds it to its Plot settings menu.

    m_rangeMenu can also be displayed by the plot widget as a context menu.

    Both accesses from the MainWindow and from the Plot Widget context menu work, but... when accessed from the context menu, the QCombobox only shows correctly on top of the menu the first time. When the context menu is invoked after that, the QComboBox is always partially hidden behind the menu. This does not happen when the menu is only accessed via the MainWindow, but that also gets broken after accessing the QMenu once from the context menu.


    m_rangeMenu is created as follows:

        m_rangeMenu = new QMenu(this);
        m_rangeMenu->setTitle("Plot Range (%FS)");
        QComboBox* rangeComboBox = new QComboBox(m_rangeMenu);
        rangeComboBox->addItem("Auto", QVariant(0));
        for (int i=10; i<=100; i+=10)
            rangeComboBox->addItem(QString::number(i), QVariant(i));
        QWidgetAction* rangeAction = new QWidgetAction(m_rangeMenu);
        CHECKED_CONNECT(rangeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(setPlotRange(int)));

    and added to the context menu as follows:

    void UmPlot::contextMenuEvent(QContextMenuEvent *event)
        QMenu menu(this);

    Why is his happening and how can I correct this?

  • Lifetime Qt Champion


    Which version of Qt are you using ?
    On which version of Windows ?

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.