mirror of
https://github.com/qgis/QGIS.git
synced 2025-11-28 00:06:23 -05:00
When holding ctrl while mouse wheeling on spin box, increase
in smaller amounts Default Qt behavior is to increase step size 10x when ctrl is held while mouse wheel - but everywhere else in QGIS UI we use the ctrl modifier as a "finer" increment with the mouse wheel (e.g. ctrl+wheel = fine zoom into map/composer). So override Qt's behavior and instead make ctrl modifier result in 1/10th usual increment for spin boxes.
This commit is contained in:
parent
4d936cea2b
commit
df9344e344
@ -117,6 +117,8 @@ Set the current value to the value defined by the clear value.
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void changeEvent( QEvent *event );
|
virtual void changeEvent( QEvent *event );
|
||||||
|
virtual void wheelEvent( QWheelEvent *event );
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -117,6 +117,8 @@ Set the current value to the value defined by the clear value.
|
|||||||
|
|
||||||
virtual void changeEvent( QEvent *event );
|
virtual void changeEvent( QEvent *event );
|
||||||
virtual void paintEvent( QPaintEvent *event );
|
virtual void paintEvent( QPaintEvent *event );
|
||||||
|
virtual void wheelEvent( QWheelEvent *event );
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -62,6 +62,28 @@ void QgsDoubleSpinBox::changeEvent( QEvent *event )
|
|||||||
mLineEdit->setShowClearButton( shouldShowClearForValue( value() ) );
|
mLineEdit->setShowClearButton( shouldShowClearForValue( value() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QgsDoubleSpinBox::wheelEvent( QWheelEvent *event )
|
||||||
|
{
|
||||||
|
double step = singleStep();
|
||||||
|
if ( event->modifiers() & Qt::ControlModifier )
|
||||||
|
{
|
||||||
|
// ctrl modifier results in finer increments - 10% of usual step
|
||||||
|
double newStep = step / 10;
|
||||||
|
// but don't ever use an increment smaller than would be visible in the widget
|
||||||
|
// i.e. if showing 2 decimals, smallest increment will be 0.01
|
||||||
|
newStep = qMax( newStep, pow( 10.0, 0.0 - decimals() ) );
|
||||||
|
|
||||||
|
setSingleStep( newStep );
|
||||||
|
|
||||||
|
// clear control modifier before handing off event - Qt uses it for unwanted purposes
|
||||||
|
// (*increasing* step size, whereas QGIS UX convention is that control modifier
|
||||||
|
// results in finer changes!)
|
||||||
|
event->setModifiers( event->modifiers() & ~Qt::ControlModifier );
|
||||||
|
}
|
||||||
|
QDoubleSpinBox::wheelEvent( event );
|
||||||
|
setSingleStep( step );
|
||||||
|
}
|
||||||
|
|
||||||
void QgsDoubleSpinBox::paintEvent( QPaintEvent *event )
|
void QgsDoubleSpinBox::paintEvent( QPaintEvent *event )
|
||||||
{
|
{
|
||||||
mLineEdit->setShowClearButton( shouldShowClearForValue( value() ) );
|
mLineEdit->setShowClearButton( shouldShowClearForValue( value() ) );
|
||||||
|
|||||||
@ -125,6 +125,7 @@ class GUI_EXPORT QgsDoubleSpinBox : public QDoubleSpinBox
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void changeEvent( QEvent *event ) override;
|
virtual void changeEvent( QEvent *event ) override;
|
||||||
|
void wheelEvent( QWheelEvent *event ) override;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void changed( double value );
|
void changed( double value );
|
||||||
|
|||||||
@ -68,6 +68,27 @@ void QgsSpinBox::paintEvent( QPaintEvent *event )
|
|||||||
QSpinBox::paintEvent( event );
|
QSpinBox::paintEvent( event );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QgsSpinBox::wheelEvent( QWheelEvent *event )
|
||||||
|
{
|
||||||
|
int step = singleStep();
|
||||||
|
if ( event->modifiers() & Qt::ControlModifier )
|
||||||
|
{
|
||||||
|
// ctrl modifier results in finer increments - 10% of usual step
|
||||||
|
int newStep = step / 10;
|
||||||
|
// step should be at least 1
|
||||||
|
newStep = qMax( newStep, 1 );
|
||||||
|
|
||||||
|
setSingleStep( newStep );
|
||||||
|
|
||||||
|
// clear control modifier before handing off event - Qt uses it for unwanted purposes
|
||||||
|
// (*increasing* step size, whereas QGIS UX convention is that control modifier
|
||||||
|
// results in finer changes!)
|
||||||
|
event->setModifiers( event->modifiers() & ~Qt::ControlModifier );
|
||||||
|
}
|
||||||
|
QSpinBox::wheelEvent( event );
|
||||||
|
setSingleStep( step );
|
||||||
|
}
|
||||||
|
|
||||||
void QgsSpinBox::changed( int value )
|
void QgsSpinBox::changed( int value )
|
||||||
{
|
{
|
||||||
mLineEdit->setShowClearButton( shouldShowClearForValue( value ) );
|
mLineEdit->setShowClearButton( shouldShowClearForValue( value ) );
|
||||||
|
|||||||
@ -126,6 +126,7 @@ class GUI_EXPORT QgsSpinBox : public QSpinBox
|
|||||||
|
|
||||||
virtual void changeEvent( QEvent *event ) override;
|
virtual void changeEvent( QEvent *event ) override;
|
||||||
virtual void paintEvent( QPaintEvent *event ) override;
|
virtual void paintEvent( QPaintEvent *event ) override;
|
||||||
|
void wheelEvent( QWheelEvent *event ) override;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void changed( int value );
|
void changed( int value );
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user