From f3c697abe71c9847207f5087ef7faea9eea55079 Mon Sep 17 00:00:00 2001 From: wmayer Date: Fri, 11 Sep 2020 14:10:45 +0200 Subject: [PATCH] Gui: [skip ci] workaround for QWindowsStyle to disable spin buttons when it is set read-only --- src/Gui/QuantitySpinBox.cpp | 24 +++++++++++++++---- src/Gui/QuantitySpinBox.h | 1 + src/Gui/SpinBox.cpp | 48 +++++++++++++++++++++++++++++++++++++ src/Gui/SpinBox.h | 4 ++++ 4 files changed, 73 insertions(+), 4 deletions(-) diff --git a/src/Gui/QuantitySpinBox.cpp b/src/Gui/QuantitySpinBox.cpp index f2b6f057eb..5bade8721e 100644 --- a/src/Gui/QuantitySpinBox.cpp +++ b/src/Gui/QuantitySpinBox.cpp @@ -23,17 +23,19 @@ #include "PreCompiled.h" #ifndef _PreComp_ +# include # include -# include # include # include # include # include -# include -# include +# include # include +# include +# include +# include +# include # include -# include #endif #include "QuantitySpinBox.h" @@ -517,6 +519,20 @@ void Gui::QuantitySpinBox::keyPressEvent(QKeyEvent *event) QAbstractSpinBox::keyPressEvent(event); } +void Gui::QuantitySpinBox::paintEvent(QPaintEvent*) +{ + QStyleOptionSpinBox opt; + initStyleOption(&opt); + if (hasExpression()) { + opt.activeSubControls &= ~QStyle::SC_SpinBoxUp; + opt.activeSubControls &= ~QStyle::SC_SpinBoxDown; + opt.state &= ~QStyle::State_Active; + opt.stepEnabled = StepNone; + } + + QStylePainter p(this); + p.drawComplexControl(QStyle::CC_SpinBox, opt); +} void QuantitySpinBox::updateText(const Quantity &quant) { diff --git a/src/Gui/QuantitySpinBox.h b/src/Gui/QuantitySpinBox.h index 4c95deb340..61b9719c89 100644 --- a/src/Gui/QuantitySpinBox.h +++ b/src/Gui/QuantitySpinBox.h @@ -156,6 +156,7 @@ protected: virtual void focusOutEvent(QFocusEvent * event); virtual void keyPressEvent(QKeyEvent *event); virtual void resizeEvent(QResizeEvent *event); + virtual void paintEvent(QPaintEvent *event); private: void updateText(const Base::Quantity&); diff --git a/src/Gui/SpinBox.cpp b/src/Gui/SpinBox.cpp index 74d45b7c77..e751c149f7 100644 --- a/src/Gui/SpinBox.cpp +++ b/src/Gui/SpinBox.cpp @@ -29,6 +29,9 @@ # include # include # include +# include +# include +# include #endif #include "SpinBox.h" @@ -409,6 +412,21 @@ void UIntSpinBox::keyPressEvent(QKeyEvent *event) QAbstractSpinBox::keyPressEvent(event); } +void UIntSpinBox::paintEvent(QPaintEvent*) +{ + QStyleOptionSpinBox opt; + initStyleOption(&opt); + if (hasExpression()) { + opt.activeSubControls &= ~QStyle::SC_SpinBoxUp; + opt.activeSubControls &= ~QStyle::SC_SpinBoxDown; + opt.state &= ~QStyle::State_Active; + opt.stepEnabled = StepNone; + } + + QStylePainter p(this); + p.drawComplexControl(QStyle::CC_SpinBox, opt); +} + // ---------------------------------------------------------------------------- IntSpinBox::IntSpinBox(QWidget* parent) : QSpinBox(parent) { @@ -587,6 +605,21 @@ void IntSpinBox::keyPressEvent(QKeyEvent *event) QAbstractSpinBox::keyPressEvent(event); } +void IntSpinBox::paintEvent(QPaintEvent*) +{ + QStyleOptionSpinBox opt; + initStyleOption(&opt); + if (hasExpression()) { + opt.activeSubControls &= ~QStyle::SC_SpinBoxUp; + opt.activeSubControls &= ~QStyle::SC_SpinBoxDown; + opt.state &= ~QStyle::State_Active; + opt.stepEnabled = StepNone; + } + + QStylePainter p(this); + p.drawComplexControl(QStyle::CC_SpinBox, opt); +} + // ---------------------------------------------------------------------------- DoubleSpinBox::DoubleSpinBox(QWidget* parent): QDoubleSpinBox(parent) { @@ -764,4 +797,19 @@ void DoubleSpinBox::keyPressEvent(QKeyEvent *event) QAbstractSpinBox::keyPressEvent(event); } +void DoubleSpinBox::paintEvent(QPaintEvent*) +{ + QStyleOptionSpinBox opt; + initStyleOption(&opt); + if (hasExpression()) { + opt.activeSubControls &= ~QStyle::SC_SpinBoxUp; + opt.activeSubControls &= ~QStyle::SC_SpinBoxDown; + opt.state &= ~QStyle::State_Active; + opt.stepEnabled = StepNone; + } + + QStylePainter p(this); + p.drawComplexControl(QStyle::CC_SpinBox, opt); +} + #include "moc_SpinBox.cpp" diff --git a/src/Gui/SpinBox.h b/src/Gui/SpinBox.h index 14b0dffab3..7369fe08f4 100644 --- a/src/Gui/SpinBox.h +++ b/src/Gui/SpinBox.h @@ -91,6 +91,8 @@ public: void keyPressEvent(QKeyEvent *event); void resizeEvent(QResizeEvent *event); + void paintEvent(QPaintEvent *event); + Q_SIGNALS: void valueChanged( uint value ); @@ -131,6 +133,7 @@ public: void keyPressEvent(QKeyEvent *event); void resizeEvent(QResizeEvent *event); + void paintEvent(QPaintEvent *event); private Q_SLOTS: void finishFormulaDialog(); @@ -157,6 +160,7 @@ public: void keyPressEvent(QKeyEvent *event); void resizeEvent(QResizeEvent *event); + void paintEvent(QPaintEvent *event); private Q_SLOTS: void finishFormulaDialog();