In my project I display a QMenu
with several QAction
objects. I want the QAction
icon to change when the user hovers over it.
Here is my current code:
QPixmap icons(":/icons/platformIcons.png");
QIcon icon;
icon.addPixmap(icons.copy(0, 0, 16, 16), QIcon::Selected, QIcon::On);
icon.addPixmap(icons.copy(0, 16, 16, 16), QIcon::Selected, QIcon::Off);
ui->actionOpen->setIcon(icon);
However the icon doesn't change when the user hovers over the QAction
. I've tried modes Normal
and Active
and the result is the same. If I switch the states, the icon is reversed, but still doesn't change on a hover (or click for that matter).
Thanks for your time.
Support for hovering normal/active icons in menus and toolbars seems to depend on the platform style, and is not supported with native Mac styling in particular, even when disabling usage of the native menu bar (ie. having the menus show at the top of the desktop rather than within the application window).
I've made a quick try with a Qt Designer form on a Mac to replicate your use case (basically ends up as the same C++ code using
QIcon::addPixmap()
):When using the default Mac styling, I only get the red/green circle icon in the menu and the toolbar, even when hovering the mouse. However if I force another style with e.g.
ui->menuYo->setStyle(QStyleFactory::create("fusion"));
then the hovering works, but the menu doesn't look native anymore...