UI: DoubleSpinBox: Don't auto-focus on wheel event

This commit is contained in:
Nodir Temirkhodjaev 2023-11-29 11:37:48 +03:00
parent dce4e6447c
commit 6dfd4373c2
4 changed files with 39 additions and 2 deletions

View File

@ -40,6 +40,7 @@ SOURCES += \
form/controls/clickablemenu.cpp \
form/controls/combobox.cpp \
form/controls/controlutil.cpp \
form/controls/doublespinbox.cpp \
form/controls/labelcolor.cpp \
form/controls/labeldoublespin.cpp \
form/controls/labelspin.cpp \
@ -231,6 +232,7 @@ HEADERS += \
form/controls/clickablemenu.h \
form/controls/combobox.h \
form/controls/controlutil.h \
form/controls/doublespinbox.h \
form/controls/labelcolor.h \
form/controls/labeldoublespin.h \
form/controls/labelspin.h \

View File

@ -0,0 +1,18 @@
#include "doublespinbox.h"
#include <QWheelEvent>
DoubleSpinBox::DoubleSpinBox(QWidget *parent) : QDoubleSpinBox(parent)
{
setFocusPolicy(Qt::StrongFocus);
}
void DoubleSpinBox::wheelEvent(QWheelEvent *e)
{
if (!hasFocus()) {
e->ignore();
return;
}
QDoubleSpinBox::wheelEvent(e);
}

View File

@ -0,0 +1,17 @@
#ifndef DOUBLESPINBOX_H
#define DOUBLESPINBOX_H
#include <QDoubleSpinBox>
class DoubleSpinBox : public QDoubleSpinBox
{
Q_OBJECT
public:
explicit DoubleSpinBox(QWidget *parent = nullptr);
protected:
void wheelEvent(QWheelEvent *e) override;
};
#endif // DOUBLESPINBOX_H

View File

@ -1,10 +1,10 @@
#include "labeldoublespin.h"
#include <QDoubleSpinBox>
#include <QHBoxLayout>
#include <QLabel>
#include "controlutil.h"
#include "doublespinbox.h"
LabelDoubleSpin::LabelDoubleSpin(QWidget *parent) : QWidget(parent)
{
@ -29,7 +29,7 @@ void LabelDoubleSpin::setupUi()
void LabelDoubleSpin::setupSpin()
{
m_spinBox = new QDoubleSpinBox();
m_spinBox = new DoubleSpinBox();
m_spinBox->setMinimumWidth(110);
m_spinBox->setRange(0, 9999);
}