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 signal aboutToShow()
Qt 6.11 is out! See what's new in the release blog

QMenu signal aboutToShow()

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 3 Posters 2.4k 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.
  • Q Offline
    Q Offline
    Qt.Jo.Ha
    wrote on last edited by Qt.Jo.Ha
    #1

    Can I open the menu after checking it using aboutToShow?

    jsulmJ 1 Reply Last reply
    0
    • Q Qt.Jo.Ha

      Can I open the menu after checking it using aboutToShow?

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

      @Qt-Jo-Ha What do you mean? The menu will be shown after your slot connected to aboutToShow() was executed. Please explain better what you want to do.

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

      Q 1 Reply Last reply
      0
      • jsulmJ jsulm

        @Qt-Jo-Ha What do you mean? The menu will be shown after your slot connected to aboutToShow() was executed. Please explain better what you want to do.

        Q Offline
        Q Offline
        Qt.Jo.Ha
        wrote on last edited by
        #3

        @jsulm

        Before opening the menu, I want to check one value, and if it is not true, a message box will appear and the menu will not open

        Thanks for the answer

        jsulmJ 1 Reply Last reply
        0
        • Q Qt.Jo.Ha

          @jsulm

          Before opening the menu, I want to check one value, and if it is not true, a message box will appear and the menu will not open

          Thanks for the answer

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

          @Qt-Jo-Ha I don't think you can do this using aboutToShow().
          You should rethink your design: if a menu is not disabled then it should work, else user will be irritated why it is not working.
          So, you should better disable that menu if the condition is not fulfilled.

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

          Q 1 Reply Last reply
          3
          • jsulmJ jsulm

            @Qt-Jo-Ha I don't think you can do this using aboutToShow().
            You should rethink your design: if a menu is not disabled then it should work, else user will be irritated why it is not working.
            So, you should better disable that menu if the condition is not fulfilled.

            Q Offline
            Q Offline
            Qt.Jo.Ha
            wrote on last edited by
            #5

            @jsulm

            Thanks for the answer and I have 2 questions

            1. Is the way to explain the reason why it can't be used with a message box?

            2. If the menu button is active, is there any way to prevent it from opening when clicked?

            jsulmJ 1 Reply Last reply
            0
            • Q Qt.Jo.Ha

              @jsulm

              Thanks for the answer and I have 2 questions

              1. Is the way to explain the reason why it can't be used with a message box?

              2. If the menu button is active, is there any way to prevent it from opening when clicked?

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

              @Qt-Jo-Ha What should actually happen if the user clicks on the menu and the condition is true? I guess you have a slot connected to the menu? You could simply check the condition there and decide what to do.

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

              Q 1 Reply Last reply
              0
              • jsulmJ jsulm

                @Qt-Jo-Ha What should actually happen if the user clicks on the menu and the condition is true? I guess you have a slot connected to the menu? You could simply check the condition there and decide what to do.

                Q Offline
                Q Offline
                Qt.Jo.Ha
                wrote on last edited by
                #7

                @jsulm said in QMenu signal aboutToShow():

                What should actually happen if the user clicks on the menu and the condition is true? I guess you have a slot connected to the menu? You could simply check the condition there and decide what to do.

                I just want to open a menu if the condition is true when clicked. However, if the condition is false, it tries to open a message box without opening the menu.

                jsulmJ 1 Reply Last reply
                0
                • Q Qt.Jo.Ha

                  @jsulm said in QMenu signal aboutToShow():

                  What should actually happen if the user clicks on the menu and the condition is true? I guess you have a slot connected to the menu? You could simply check the condition there and decide what to do.

                  I just want to open a menu if the condition is true when clicked. However, if the condition is false, it tries to open a message box without opening the menu.

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

                  @Qt-Jo-Ha What if you call https://doc.qt.io/qt-5/qwidget.html#setDisabled (with true) inside aboutToShow() if condition is false?

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

                  Q 1 Reply Last reply
                  0
                  • jsulmJ jsulm

                    @Qt-Jo-Ha What if you call https://doc.qt.io/qt-5/qwidget.html#setDisabled (with true) inside aboutToShow() if condition is false?

                    Q Offline
                    Q Offline
                    Qt.Jo.Ha
                    wrote on last edited by
                    #9

                    @jsulm

                    Calling setDisable inside aboutToShow() also opens the menu.

                    JonBJ 1 Reply Last reply
                    0
                    • Q Qt.Jo.Ha

                      @jsulm

                      Calling setDisable inside aboutToShow() also opens the menu.

                      JonBJ Online
                      JonBJ Online
                      JonB
                      wrote on last edited by
                      #10

                      @Qt-Jo-Ha
                      I would not recommend this approach. But if you do want to persist, and aboutToShow() is too late, what about disabling during another QMenu event like hovered() or mousePressedEvent() etc.? Or, what about (perhaps creating a subclass which) intercepts QMenu::triggered or QAction::triggered and does your work there, only passing the signal onto your original action triggered slot if the condition passes? Something along these lines, depending on exactly where you wish to catch the user's action.

                      1 Reply Last reply
                      2

                      • Login

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