mirror of
https://github.com/tnodir/fort
synced 2024-11-15 08:25:20 +00:00
UI: Focus in menu widgets
This commit is contained in:
parent
4eda74f415
commit
c90ef43a5d
@ -43,6 +43,7 @@ SOURCES += \
|
||||
form/controls/combobox.cpp \
|
||||
form/controls/controlutil.cpp \
|
||||
form/controls/doublespinbox.cpp \
|
||||
form/controls/focusablemenu.cpp \
|
||||
form/controls/labelcolor.cpp \
|
||||
form/controls/labeldoublespin.cpp \
|
||||
form/controls/labelspin.cpp \
|
||||
@ -246,6 +247,7 @@ HEADERS += \
|
||||
form/controls/combobox.h \
|
||||
form/controls/controlutil.h \
|
||||
form/controls/doublespinbox.h \
|
||||
form/controls/focusablemenu.h \
|
||||
form/controls/labelcolor.h \
|
||||
form/controls/labeldoublespin.h \
|
||||
form/controls/labelspin.h \
|
||||
|
@ -18,7 +18,7 @@ protected:
|
||||
void mouseReleaseEvent(QMouseEvent *event) override;
|
||||
|
||||
private:
|
||||
bool m_pressed = false;
|
||||
bool m_pressed : 1 = false;
|
||||
};
|
||||
|
||||
#endif // CLICKABLEMENU_H
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include <util/iconcache.h>
|
||||
|
||||
#include "combobox.h"
|
||||
#include "focusablemenu.h"
|
||||
#include "labelcolor.h"
|
||||
#include "labeldoublespin.h"
|
||||
#include "labelspin.h"
|
||||
@ -218,7 +219,7 @@ QMenu *ControlUtil::createMenu(QWidget *parent)
|
||||
|
||||
QMenu *ControlUtil::createMenuByLayout(QBoxLayout *layout, QWidget *parent)
|
||||
{
|
||||
auto menu = createMenu(parent);
|
||||
auto menu = new FocusableMenu(parent);
|
||||
auto wa = new QWidgetAction(menu);
|
||||
|
||||
auto menuWidget = new MenuWidget(menu, wa);
|
||||
|
30
src/ui/form/controls/focusablemenu.cpp
Normal file
30
src/ui/form/controls/focusablemenu.cpp
Normal file
@ -0,0 +1,30 @@
|
||||
#include "focusablemenu.h"
|
||||
|
||||
#include <QEvent>
|
||||
#include <QKeyEvent>
|
||||
|
||||
FocusableMenu::FocusableMenu(QWidget *parent) : QMenu(parent)
|
||||
{
|
||||
setAttribute(Qt::WA_WindowPropagation); // to inherit default font
|
||||
}
|
||||
|
||||
bool FocusableMenu::event(QEvent *e)
|
||||
{
|
||||
switch (e->type()) {
|
||||
case QEvent::KeyPress: {
|
||||
QKeyEvent *ke = static_cast<QKeyEvent *>(e);
|
||||
if (ke->key() == Qt::Key_Tab || ke->key() == Qt::Key_Backtab) {
|
||||
return QWidget::event(e);
|
||||
}
|
||||
} break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return QMenu::event(e);
|
||||
}
|
||||
|
||||
bool FocusableMenu::focusNextPrevChild(bool next)
|
||||
{
|
||||
return QWidget::focusNextPrevChild(next);
|
||||
}
|
18
src/ui/form/controls/focusablemenu.h
Normal file
18
src/ui/form/controls/focusablemenu.h
Normal file
@ -0,0 +1,18 @@
|
||||
#ifndef FOCUSABLEMENU_H
|
||||
#define FOCUSABLEMENU_H
|
||||
|
||||
#include <QMenu>
|
||||
|
||||
class FocusableMenu : public QMenu
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit FocusableMenu(QWidget *parent = nullptr);
|
||||
|
||||
protected:
|
||||
bool event(QEvent *e) override;
|
||||
bool focusNextPrevChild(bool next) override;
|
||||
};
|
||||
|
||||
#endif // FOCUSABLEMENU_H
|
Loading…
Reference in New Issue
Block a user