Important: Please read the Qt Code of Conduct -

QStyleOptionMenuItem : need to know to position of the menu item

  • Hi all,

    I'm making a custom QStyle class, and while implementing the DrawControl() function for displaying menu items (CE_MenuItem control), I need to know the position of the menu item in the menu (in fact, I need to know whether it is first or last).

    Unfortunately, the passed QStyleOption * (which is casted to QStyleOptionMenuItem) does not provide that information.
    Neither the passed QWidget * pointer which contain the whole menu.

    I tried iterating over widget->actions() to compare the text() of the QAction menu item with the QStyleOptionMenuItem::text() but there are two difficulties :

    1. QAction::text() contains only the menu item text, whereas QStyleOptionMenuItem::text() contains both menu item text and shortcut
    2. there seem to be a lot of 'empty' QAction so that the list of the viewed menu items does not match the list of QActions in terms of indices

    Any suggestions ?


Log in to reply