Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Open a pop-up menu
QtWS25 Last Chance

Open a pop-up menu

Scheduled Pinned Locked Moved Mobile and Embedded
9 Posts 3 Posters 5.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.
  • D Offline
    D Offline
    dpatrick
    wrote on last edited by
    #1

    Hello All,

    I created a QGraphicsView with a menu, and after I selected the proper item I would like to return the selected item.

    However, when I call the show method, it is not blocked waiting the window be finished.

    How can I do it?

    Thanks all,

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      can you please post a code snippet where the problem occurs?
      From your description, it's not clear to me what you do exactly. But I can try to guess a bit:

      you call show() on the menu?

      The I should quote from the "docs:":http://doc.qt.nokia.com/4.7/qmenu.html#details

      bq. Warning: To make QMenu visible on the screen, exec() or popup() should be used instead of show().

      • exec() calls a modal event loop so the menu must be closed to go on.
      • popup() displays the menu and goes on in the execution logic, wiothout waiting for input.

      So perhaps, exec() is the one you were locking for?

      Enough crystal ball now :-)

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

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

        Thanks for your reply.
        But my class does not have the exec() and popup() methods.
        It is a QGraphicsView class.

        See header below:
        @
        class MyMenu : public QGraphicsView
        {
        public:
        MyMenu();
        void createMenu();

        protected:
        void keyPressEvent(QKeyEvent* event);
        void drawBackground(QPainter *painter, const QRectF &rect);

        private:
        MyItem *btnPage[CPAGE];
        QGraphicsScene *scene;
        QGraphicsItem *buttonParent;

        };
        @

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          You said in your first post that you call show() on your menu. Gerolf suggested that you use exec() or popup() on your menu instead. Could you show us the code (not header) where you actually show the menu?

          1 Reply Last reply
          0
          • G Offline
            G Offline
            giesbert
            wrote on last edited by
            #5

            That is not a menu. A menu is normally derived from QMenu?
            You are creating a QGraphicsView. A QGraphicsView is not a menu.

            Did you call show on the class MyMenu or on a QMenu class?

            Nokia Certified Qt Specialist.
            Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

            1 Reply Last reply
            0
            • D Offline
              D Offline
              dpatrick
              wrote on last edited by
              #6

              I am not using QMenu, I created my own Graphic Menu through QGraphicsView. So, I would like to know if it is possible to show a QGraphicsView as a popup menu.

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andre
                wrote on last edited by
                #7

                Yes, of course it is, but you will have to handle the pop-up aspect of it yourself. Take a look at the QMenu sources for inspiration on how you might achieve that.

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  giesbert
                  wrote on last edited by
                  #8

                  You must set the window flags in the constructor as popup (see QWidgetDocumentation). Opening the menu should be the same as in QMenu (look at the sources) so you should add exec / popup and implement it the same way as QMenu.

                  Nokia Certified Qt Specialist.
                  Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    dpatrick
                    wrote on last edited by
                    #9

                    I used a signal/slot to communicate when the menu is selected. Thanks all.

                    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