Solved 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 -
-
@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 Well then the only option is to use the private function
__popup
. -
@p3c0 then i have to try with that, how can i use that ?
-
@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) } }
-
@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 Glad that it worked. The first argument which takes
QRect
is used to specify the position of the menu frame. AFAIK the second i.eatItemIndex
can be used to position the menu at that particular menu index whereas the third i.emenuType
can be used to specify its types viz.DefaultMenu
andEditMenu
.
Almost all of the times 2nd and 3rd should be 0. -
@p3c0 Thanks for the information,one more question, Can i increase the height of the menu frame?
-
@Naveen_D I think it should be possible with the QRect.
-
@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.
-
@p3c0 Ok sir thank you. it helped me alot.