qt: Disable alt key menu navigation with style override

This commit is contained in:
ts-korhonen
2021-12-12 18:19:44 +02:00
parent cc909078c1
commit 03c077dfa7
4 changed files with 35 additions and 1 deletions

View File

@@ -92,6 +92,9 @@ add_library(ui STATIC
qt_soundgain.cpp
qt_soundgain.ui
qt_styleoverride.cpp
qt_styleoverride.hpp
../qt_resources.qrc
)
if (APPLE)

View File

@@ -27,7 +27,7 @@ Q_IMPORT_PLUGIN(QWindowsVistaStylePlugin)
#include "qt_mainwindow.hpp"
#include "cocoa_mouse.hpp"
#include "qt_styleoverride.hpp"
// Void Cast
#define VC(x) const_cast<wchar_t*>(x)
@@ -89,6 +89,7 @@ main_thread_fn()
int main(int argc, char* argv[]) {
QApplication app(argc, argv);
app.setStyle(new StyleOverride());
#ifdef __APPLE__
CocoaEventFilter cocoafilter;
app.installNativeEventFilter(&cocoafilter);

View File

@@ -0,0 +1,14 @@
#include "qt_styleoverride.hpp"
int StyleOverride::styleHint(
StyleHint hint,
const QStyleOption *option,
const QWidget *widget,
QStyleHintReturn *returnData) const
{
/* Disable using menu with alt key */
if (hint == QStyle::SH_MenuBar_AltKeyNavigation)
return 0;
return QProxyStyle::styleHint(hint, option, widget, returnData);
}

View File

@@ -0,0 +1,16 @@
#ifndef QT_STYLEOVERRIDE_HPP
#define QT_STYLEOVERRIDE_HPP
#include <QProxyStyle>
class StyleOverride : public QProxyStyle
{
public:
int styleHint(
StyleHint hint,
const QStyleOption *option = nullptr,
const QWidget *widget = nullptr,
QStyleHintReturn *returnData = nullptr) const override;
};
#endif