Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Qml Menu
Qt 6.11 is out! See what's new in the release blog

Qml Menu

Scheduled Pinned Locked Moved Solved QML and Qt Quick
13 Posts 2 Posters 6.8k Views 2 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.
  • Naveen_DN Offline
    Naveen_DN Offline
    Naveen_D
    wrote on last edited by
    #1

    Hi all,

    I am using qml menu in my project, based on mouse click i am poping up the menu. I want my menu to popup exactly at bottom or left of an item, which is placed at the top right corner of my application window. how can i do that? can anyone suggest me the possible solution.
    Thanks

    Naveen_D

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      @Naveen_D See this example here. Just set the x position in addition to it.

      157

      Naveen_DN 1 Reply Last reply
      0
      • p3c0P p3c0

        @Naveen_D See this example here. Just set the x position in addition to it.

        Naveen_DN Offline
        Naveen_DN Offline
        Naveen_D
        wrote on last edited by
        #3

        @p3c0 Sir i am using Qt 5.6, sorry forgot to mention. i tried with x, for that i need to import QtQuick.controls 2

        Naveen_D

        1 Reply Last reply
        0
        • p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

          @Naveen_D Well then the only option is to use the private function __popup.

          157

          Naveen_DN 1 Reply Last reply
          0
          • p3c0P p3c0

            @Naveen_D Well then the only option is to use the private function __popup.

            Naveen_DN Offline
            Naveen_DN Offline
            Naveen_D
            wrote on last edited by
            #5

            @p3c0 then i have to try with that, how can i use that ?

            Naveen_D

            1 Reply Last reply
            0
            • p3c0P Offline
              p3c0P Offline
              p3c0
              Moderators
              wrote on last edited by
              #6

              @Naveen_D Yes it is the only option with that version. Try this:

              import QtQuick 2.6
              import QtQuick.Controls 1.4
              
              Item {
                  width: 500
                  height: 500
              
                  Menu {
                      id: menu
              
                      MenuItem {
                          text: "New..."
                      }
                      MenuItem {
                          text: "Open..."
                      }
                      MenuItem {
                          text: "Exit"
                      }
                  }
              
                  Button {
                      id: btn
                      text: "Click"
                      anchors.right: parent.right
                      onClicked: menu.__popup(Qt.rect(btn.x, btn.height, 0, 0), 0, 0)
                  }
              }
              

              157

              Naveen_DN 1 Reply Last reply
              0
              • p3c0P p3c0

                @Naveen_D Yes it is the only option with that version. Try this:

                import QtQuick 2.6
                import QtQuick.Controls 1.4
                
                Item {
                    width: 500
                    height: 500
                
                    Menu {
                        id: menu
                
                        MenuItem {
                            text: "New..."
                        }
                        MenuItem {
                            text: "Open..."
                        }
                        MenuItem {
                            text: "Exit"
                        }
                    }
                
                    Button {
                        id: btn
                        text: "Click"
                        anchors.right: parent.right
                        onClicked: menu.__popup(Qt.rect(btn.x, btn.height, 0, 0), 0, 0)
                    }
                }
                
                Naveen_DN Offline
                Naveen_DN Offline
                Naveen_D
                wrote on last edited by
                #7

                @p3c0 Thank you, can i know what are those arguments inside the brackets ?
                i am able to place the menu below the rectangle.

                Naveen_D

                1 Reply Last reply
                0
                • p3c0P Offline
                  p3c0P Offline
                  p3c0
                  Moderators
                  wrote on last edited by
                  #8

                  @Naveen_D Glad that it worked. The first argument which takes QRect is used to specify the position of the menu frame. AFAIK the second i.e atItemIndex can be used to position the menu at that particular menu index whereas the third i.e menuType can be used to specify its types viz. DefaultMenu and EditMenu.
                  Almost all of the times 2nd and 3rd should be 0.

                  157

                  Naveen_DN 1 Reply Last reply
                  1
                  • p3c0P p3c0

                    @Naveen_D Glad that it worked. The first argument which takes QRect is used to specify the position of the menu frame. AFAIK the second i.e atItemIndex can be used to position the menu at that particular menu index whereas the third i.e menuType can be used to specify its types viz. DefaultMenu and EditMenu.
                    Almost all of the times 2nd and 3rd should be 0.

                    Naveen_DN Offline
                    Naveen_DN Offline
                    Naveen_D
                    wrote on last edited by
                    #9

                    @p3c0 Thanks for the information,one more question, Can i increase the height of the menu frame?

                    Naveen_D

                    1 Reply Last reply
                    0
                    • p3c0P Offline
                      p3c0P Offline
                      p3c0
                      Moderators
                      wrote on last edited by
                      #10

                      @Naveen_D I think it should be possible with the QRect.

                      157

                      Naveen_DN 1 Reply Last reply
                      0
                      • p3c0P p3c0

                        @Naveen_D I think it should be possible with the QRect.

                        Naveen_DN Offline
                        Naveen_DN Offline
                        Naveen_D
                        wrote on last edited by Naveen_D
                        #11

                        @p3c0 When i try to increase the height in the Qt.Rect, i.e
                        settingsMenu.__popup(Qt.rect(settingsimgrect.x, settingsimgrect.height,0,30),0,0)
                        instead of settingsimgrect.height if i give some other value, Menu frame height is not increased, but the height between the menu popup and the rectangle is increased. the changes what i am doing are correct ? if there is any mistake pls rectify. Thanks

                        Naveen_D

                        1 Reply Last reply
                        0
                        • p3c0P Offline
                          p3c0P Offline
                          p3c0
                          Moderators
                          wrote on last edited by
                          #12

                          @Naveen_D Yes you are right. It doesn't seem to work (I also tried by using MenuStyle). This only makes me think that since this is a private function (those which are not made public yet) it is not fully functional and they may also remove it from future releases. So for now you will need to continue as it is or switch to newer QQC2.

                          157

                          Naveen_DN 1 Reply Last reply
                          0
                          • p3c0P p3c0

                            @Naveen_D Yes you are right. It doesn't seem to work (I also tried by using MenuStyle). This only makes me think that since this is a private function (those which are not made public yet) it is not fully functional and they may also remove it from future releases. So for now you will need to continue as it is or switch to newer QQC2.

                            Naveen_DN Offline
                            Naveen_DN Offline
                            Naveen_D
                            wrote on last edited by
                            #13

                            @p3c0 Ok sir thank you. it helped me alot.

                            Naveen_D

                            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