Qml Menu
-
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 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_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_D Glad that it worked. The first argument which takes
QRectis used to specify the position of the menu frame. AFAIK the second i.eatItemIndexcan be used to position the menu at that particular menu index whereas the third i.emenuTypecan be used to specify its types viz.DefaultMenuandEditMenu.
Almost all of the times 2nd and 3rd should be 0. -
@Naveen_D Glad that it worked. The first argument which takes
QRectis used to specify the position of the menu frame. AFAIK the second i.eatItemIndexcan be used to position the menu at that particular menu index whereas the third i.emenuTypecan be used to specify its types viz.DefaultMenuandEditMenu.
Almost all of the times 2nd and 3rd should be 0. -
@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 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_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.