I know this is marked as solved but just wanted to add my 2 cents.
I did this by adding a property int type and a signal with a argument in my button, then calling the mouse click handler would invoke the signal with the type argument. Then outside on your menu were you have all your buttons, each button click will call another menu signal that receives the button type. Then you just add a bunch of if else's or a switch case to handle every type of button. Something like this:
Pill.qml:
Rectangle {
id: pill
property int type
signal btnClick(btnSignal: int)
MouseArea {
anchors.fill: parent
onClicked: btnClick(type)
}
}
Then on your menu:
signal handlePills(type: int)
onHandlePills: function(type){
if (type === stuff1)
doStuff1()
if (type === stuff2)
doStuff2()
.......
}
Pill {
type: stuff1
onBtnClick: handlePills(type)
}
Pill {
type: stuff2
onBtnClick: handlePills(type)
}
To make this more elegant you can create a qml enum and use it on type. I dont know your use case but to me was less error prone and more elegant code.
Taking another step further, and since I needed a dynamic menu where I could add or remove buttons, I created a listview, a model and button delegate, to create the menu with buttons. Then only took me a line of code to add a button:
function showMenuCommands() {
menuCommands.modelMenu.clear()
menuCommands.modelMenu.append({"textName": "copy", "typeName": Commands.Copy})
menuCommands.modelMenu.append({"textName": "move", "typeName": Commands.Move})
menuCommands.modelMenu.append({"textName": "scale", "typeName": Commands.Scale})
........
}