summaryrefslogtreecommitdiffstats
path: root/src/widgets/widgets/qspinbox.h
diff options
context:
space:
mode:
authorHarald Nordgren <haraldnordgren@gmail.com>2016-03-28 23:07:46 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2018-03-22 21:37:45 +0000
commit97e40a5409dd4338084fe8df2397156dccc49d6d (patch)
tree4356837b5cc6cb2e1e8ed858d745743424380500 /src/widgets/widgets/qspinbox.h
parenta692d7cd2804ead51aef8670c9fbb098c117ebf6 (diff)
Allow adaptive decimal stepping for QSpinBox and QDoubleSpinBox
Adds the feature of adaptive decimal step sizes for the QSpinBox and QDoubleSpinBox. By performing a calculation in QAbstractSpinBox::stepBy() we continuously set the step size one power of ten below the current value. So when the value is 1100, the step is set to 100, so stepping up once increases it to 1200. For 1200 stepping up takes it to 1300. For negative values stepping down from -1100 goes to -1200. It also works for all decimal values. 0.041 is increased to 0.042 by stepping once, and so on. The step direction is taken into account to handle edges cases, so that stepping down from 100 takes the value to 99 instead of 90. Thus, a step up followed by a step down -- or vice versa -- lands on the starting value; 99 -> 100 -> 99. Setting this property effectively disregards singleStep, but preserves its value so that it takes effect again when adaptive decimal step is disabled. Adaptive decimal step allows values to be easily set to reasonable levels. If the spin box value is 12000, changing to 13000 often makes more sense than to 12001. The feature is turned off be default, when single stepping is desired. The accelerated property allows values to be changed quickly, as well, but it is imprecise. Holding down the button makes it hard to land on an even thousand, like 12000 or 13000. Often you end up somewhere nearby and would need a second adjustment to get to an even hundred or thousand. [ChangeLog][QtWidgets] Add option of adaptive decimal step size for QSpinBox and QDoubleSpinBox. Change-Id: I9f286479b821e240c8ea05c238932fc128c582bb Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'src/widgets/widgets/qspinbox.h')
-rw-r--r--src/widgets/widgets/qspinbox.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/widgets/widgets/qspinbox.h b/src/widgets/widgets/qspinbox.h
index 73489c9a68..d2eac903fb 100644
--- a/src/widgets/widgets/qspinbox.h
+++ b/src/widgets/widgets/qspinbox.h
@@ -58,6 +58,7 @@ class Q_WIDGETS_EXPORT QSpinBox : public QAbstractSpinBox
Q_PROPERTY(int minimum READ minimum WRITE setMinimum)
Q_PROPERTY(int maximum READ maximum WRITE setMaximum)
Q_PROPERTY(int singleStep READ singleStep WRITE setSingleStep)
+ Q_PROPERTY(StepType stepType READ stepType WRITE setStepType)
Q_PROPERTY(int value READ value WRITE setValue NOTIFY valueChanged USER true)
Q_PROPERTY(int displayIntegerBase READ displayIntegerBase WRITE setDisplayIntegerBase)
@@ -86,6 +87,9 @@ public:
void setRange(int min, int max);
+ StepType stepType() const;
+ void setStepType(StepType stepType);
+
int displayIntegerBase() const;
void setDisplayIntegerBase(int base);
@@ -121,6 +125,7 @@ class Q_WIDGETS_EXPORT QDoubleSpinBox : public QAbstractSpinBox
Q_PROPERTY(double minimum READ minimum WRITE setMinimum)
Q_PROPERTY(double maximum READ maximum WRITE setMaximum)
Q_PROPERTY(double singleStep READ singleStep WRITE setSingleStep)
+ Q_PROPERTY(StepType stepType READ stepType WRITE setStepType)
Q_PROPERTY(double value READ value WRITE setValue NOTIFY valueChanged USER true)
public:
explicit QDoubleSpinBox(QWidget *parent = nullptr);
@@ -147,6 +152,9 @@ public:
void setRange(double min, double max);
+ StepType stepType() const;
+ void setStepType(StepType stepType);
+
int decimals() const;
void setDecimals(int prec);