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. Popup Menu in QOpenGLWindow - how to do it?
Forum Updated to NodeBB v4.3 + New Features

Popup Menu in QOpenGLWindow - how to do it?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 445 Views 1 Watching
  • 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.
  • D Offline
    D Offline
    DavidRS
    wrote on last edited by
    #1

    I have a program that processes data and then generates an image which is then displayed in a QOpenGLWidow. I would like to have a popup menu on right mouse click to give a list of display options. The menu changes according to the properties of the data/image.

    As far as I can see, QOpenGLWindow (and QWindow) do not have a contextMenuPolicy, so trying to detect a contextMenuEvent on a right click (as below) fails and nothing happens

    void ViewData::contextMenuEvent(QContextMenuEvent *e)
    {
          QMenu* menu =imageMenu;
          menu->exec(e->globalPos());
    }
    

    I wondered if creating a QContextMenuEvent on a right mouse click might help, but I'm not sure how to transmit it and by itself it does nothing.

    jsulmJ 1 Reply Last reply
    0
    • D DavidRS

      I have a program that processes data and then generates an image which is then displayed in a QOpenGLWidow. I would like to have a popup menu on right mouse click to give a list of display options. The menu changes according to the properties of the data/image.

      As far as I can see, QOpenGLWindow (and QWindow) do not have a contextMenuPolicy, so trying to detect a contextMenuEvent on a right click (as below) fails and nothing happens

      void ViewData::contextMenuEvent(QContextMenuEvent *e)
      {
            QMenu* menu =imageMenu;
            menu->exec(e->globalPos());
      }
      

      I wondered if creating a QContextMenuEvent on a right mouse click might help, but I'm not sure how to transmit it and by itself it does nothing.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @DavidRS You could simply show the pop-up menu on right-click without transmitting QContextMenuEvent

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • D Offline
        D Offline
        DavidRS
        wrote on last edited by DavidRS
        #3

        Nope. If you do the following

        void ViewData::mousePressEvent(QMouseEvent *e)
        {
          switch(e->button())
          {
            // code for other buttons before here
              case (Qt::RightButton)
              {
                imageMenu->exec(e->globalPos());
                break;
              }
         }
        

        The program crashes when you right click.
        This is running under Linux and X11 with Qt ver 5.13.2

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          Might be a silly question but are you sure that imageMenu is valid ?

          Can you show the stack trace you get ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          D 1 Reply Last reply
          1
          • SGaistS SGaist

            Hi,

            Might be a silly question but are you sure that imageMenu is valid ?

            Can you show the stack trace you get ?

            D Offline
            D Offline
            DavidRS
            wrote on last edited by
            #5

            @SGaist You were right - the QMenu initialization was in a branch that was not being visited. Once I moved it before that branch it worked perfectly. Because there are no widgets the menu was created as

            imageMenu = new QMenu(nullptr);
            

            and was directly accessed through the right mouse click once the image was created.

            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