Skip to content

Commit e2c84f1

Browse files
authoredJul 8, 2017
Merge pull request #4669 from nyalldawson/spinbox_ctrl
When holding ctrl while mouse wheeling on spin box, increase in smaller amounts
2 parents 8f8cb67 + df9344e commit e2c84f1

File tree

6 files changed

+49
-0
lines changed

6 files changed

+49
-0
lines changed
 

‎python/gui/editorwidgets/qgsdoublespinbox.sip

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ Set the current value to the value defined by the clear value.
117117

118118
protected:
119119
virtual void changeEvent( QEvent *event );
120+
virtual void wheelEvent( QWheelEvent *event );
121+
120122

121123
};
122124

‎python/gui/editorwidgets/qgsspinbox.sip

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ Set the current value to the value defined by the clear value.
117117

118118
virtual void changeEvent( QEvent *event );
119119
virtual void paintEvent( QPaintEvent *event );
120+
virtual void wheelEvent( QWheelEvent *event );
121+
120122

121123
};
122124

‎src/gui/editorwidgets/qgsdoublespinbox.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,28 @@ void QgsDoubleSpinBox::changeEvent( QEvent *event )
6262
mLineEdit->setShowClearButton( shouldShowClearForValue( value() ) );
6363
}
6464

65+
void QgsDoubleSpinBox::wheelEvent( QWheelEvent *event )
66+
{
67+
double step = singleStep();
68+
if ( event->modifiers() & Qt::ControlModifier )
69+
{
70+
// ctrl modifier results in finer increments - 10% of usual step
71+
double newStep = step / 10;
72+
// but don't ever use an increment smaller than would be visible in the widget
73+
// i.e. if showing 2 decimals, smallest increment will be 0.01
74+
newStep = qMax( newStep, pow( 10.0, 0.0 - decimals() ) );
75+
76+
setSingleStep( newStep );
77+
78+
// clear control modifier before handing off event - Qt uses it for unwanted purposes
79+
// (*increasing* step size, whereas QGIS UX convention is that control modifier
80+
// results in finer changes!)
81+
event->setModifiers( event->modifiers() & ~Qt::ControlModifier );
82+
}
83+
QDoubleSpinBox::wheelEvent( event );
84+
setSingleStep( step );
85+
}
86+
6587
void QgsDoubleSpinBox::paintEvent( QPaintEvent *event )
6688
{
6789
mLineEdit->setShowClearButton( shouldShowClearForValue( value() ) );

‎src/gui/editorwidgets/qgsdoublespinbox.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ class GUI_EXPORT QgsDoubleSpinBox : public QDoubleSpinBox
125125

126126
protected:
127127
virtual void changeEvent( QEvent *event ) override;
128+
void wheelEvent( QWheelEvent *event ) override;
128129

129130
private slots:
130131
void changed( double value );

‎src/gui/editorwidgets/qgsspinbox.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,27 @@ void QgsSpinBox::paintEvent( QPaintEvent *event )
6868
QSpinBox::paintEvent( event );
6969
}
7070

71+
void QgsSpinBox::wheelEvent( QWheelEvent *event )
72+
{
73+
int step = singleStep();
74+
if ( event->modifiers() & Qt::ControlModifier )
75+
{
76+
// ctrl modifier results in finer increments - 10% of usual step
77+
int newStep = step / 10;
78+
// step should be at least 1
79+
newStep = qMax( newStep, 1 );
80+
81+
setSingleStep( newStep );
82+
83+
// clear control modifier before handing off event - Qt uses it for unwanted purposes
84+
// (*increasing* step size, whereas QGIS UX convention is that control modifier
85+
// results in finer changes!)
86+
event->setModifiers( event->modifiers() & ~Qt::ControlModifier );
87+
}
88+
QSpinBox::wheelEvent( event );
89+
setSingleStep( step );
90+
}
91+
7192
void QgsSpinBox::changed( int value )
7293
{
7394
mLineEdit->setShowClearButton( shouldShowClearForValue( value ) );

‎src/gui/editorwidgets/qgsspinbox.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ class GUI_EXPORT QgsSpinBox : public QSpinBox
126126

127127
virtual void changeEvent( QEvent *event ) override;
128128
virtual void paintEvent( QPaintEvent *event ) override;
129+
void wheelEvent( QWheelEvent *event ) override;
129130

130131
private slots:
131132
void changed( int value );

0 commit comments

Comments
 (0)
Please sign in to comment.