Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QMenu Context Submenu Problem Qt 5.0.1 Mac

QMenu Context Submenu Problem Qt 5.0.1 Mac

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 2.9k Views
  • 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 Offline
    P Offline
    PixelDelirium
    wrote on last edited by
    #1

    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
    0
    • P Offline
      P Offline
      PixelDelirium
      wrote on last edited by
      #2

      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
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved