[Solved] QMenu item/action pre selection
I am using a contextMenu and just want to know if there is any possibility that when the contextMenu is displayed a particular item/action is represented as selected, just like a QListView/QListWidget.
a context menu is build up of QMenu items, which essentially are buttons.
You can use the cursor keys, but it sounds odd to 'pre-select' something. Its not a selectable thing.
What you may be thinking of is that you position the menu such that the item you want is under the cursor. And this you can do yourself, you just use the QPoint you pass when popping up the menu. Calculate the offset to your wanted item (based on the height of the buttons), and subtract that from the popup position.
For the current requirement the contextMenu is associated with a pushButton i.e the position of the context menu is fixed, The button hold some property which is listed in the contextMenu, So when the contextMenu is displayed the current property of the pushButton is shown as selected in the menu, the user can change the property by selecting other items from the same.
I have another implementation where I am using a listWidget that shows all properties and is added using QWidgetAction to the contextMenu. This implementation works as required, so i think i'll stick to this as of now.