Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Call for Presentations - Qt World Summit

    QMenu Context Submenu Problem Qt 5.0.1 Mac

    General and Desktop
    1
    2
    2799
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • P
      PixelDelirium last edited by

      When porting my Qt 4.8 application to Qt 5 actions in submenus on context menus are not working properly on the Mac version of Qt 5.0.1. Whenever an item in a submenu is selected the submenu disappears but the main context menu does not exit and the exec() doesn't return. Actions on the main menu work as expected. It works on Windows Qt 5. Am I missing something or is this a bug? Here is a simple test case:

      mainwindow.h:
      @
      #include <QMainWindow>

      namespace Ui {
      class MainWindow;
      }

      class MainWindow : public QMainWindow
      {
      Q_OBJECT

      public:
      explicit MainWindow(QWidget *parent = 0);
      ~MainWindow();

      public slots:
      void contextMenu(QPoint p);
      };
      @

      mainwindow.cpp:
      @
      #include "mainwindow.h"

      #include <QDebug>
      #include <QAction>
      #include <QDebug>
      #include <QMenu>

      MainWindow::MainWindow(QWidget *parent) :
      QMainWindow(parent)
      {
      this->setContextMenuPolicy(Qt::CustomContextMenu);
      connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenu(QPoint)));
      }

      MainWindow::~MainWindow()
      {
      }

      void MainWindow::contextMenu(QPoint p) {
      QMenu menu;
      menu.addMenu("Test")->addAction("This Is A Test");

      QAction *a = menu.exec&#40;pos(&#41;+p&#41;;
      
      if(a) {
          qDebug() << "Action:" << a->text();
      } else {
          qDebug() << "No action selected";
      }
      

      }
      @

      1 Reply Last reply Reply Quote 0
      • P
        PixelDelirium last edited by

        This seems to work as a work around for now:

        @
        void MainWindow::contextMenu(QPoint p) {
        QMenu menu;
        QMenu *testMenu = menu.addMenu("Test");
        QAction *testAction = testMenu->addAction("This Is A Test");

        connect(testAction, SIGNAL(triggered()), &menu, SLOT(close()));
        
        QAction *a = menu.exec&#40;pos(&#41;+p);
        
        if(a) {
            qDebug() << "Action:" << a->text();
        } else {
            qDebug() << "No action selected";
        }
        

        }
        @

        1 Reply Last reply Reply Quote 0
        • First post
          Last post