In my application, I need to change my mouse cursor and do some stuff differently once the Alt
key is pressed, and go back to the normal cursor and normal behavior once the Alt
key is released.
Everything works fine on Mac OS, while the Alt
-pressing event moves the focus to the menubar on Windows (native Windows behavior), which results in unexpected behaviors of my cursor-changing desire.
So the question is: how to disable this Windows feature (code-wise in Qt of course) and always pass the Alt
key press event to the application itself instead of the menubar.
SH_MenuBar_AltKeyNavigation style hint responsible for menubar selection after Alt pressed. You need to subclass QProxyStyle and override styleHint
method like this:
class MenuStyle : public QProxyStyle
{
public:
int styleHint(StyleHint stylehint, const QStyleOption *opt, const QWidget *widget, QStyleHintReturn *returnData) const
{
if (stylehint == QStyle::SH_MenuBar_AltKeyNavigation)
return 0;
return QProxyStyle::styleHint(stylehint, opt, widget, returnData);
}
};
Then, set custom style to application.
QApplication a(argc, argv);
a.setStyle(new MenuStyle());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With