mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-13 00:03:09 -04:00
Allow QgsScrollArea to maintain horizontal width of area for
child widgets, and apply scroll area to vertical contents only
This commit is contained in:
parent
5a57336880
commit
ffe02c37b6
@ -45,11 +45,23 @@ QScrollArea itself or its child viewport().
|
||||
%Docstring
|
||||
Returns ``True`` if a scroll recently occurred within
|
||||
the QScrollArea or its child viewport()
|
||||
%End
|
||||
|
||||
void setVerticalOnly( bool verticalOnly );
|
||||
%Docstring
|
||||
Sets whether the scroll area only applies vertical.
|
||||
|
||||
If set to ``True``, then scroll area children will resize horizontally to match the width of
|
||||
the scroll area widget.
|
||||
|
||||
.. versionadded:: 3.8
|
||||
%End
|
||||
|
||||
protected:
|
||||
virtual void wheelEvent( QWheelEvent *event );
|
||||
|
||||
virtual void resizeEvent( QResizeEvent *event );
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
@ -34,6 +34,13 @@ void QgsScrollArea::wheelEvent( QWheelEvent *e )
|
||||
QScrollArea::wheelEvent( e );
|
||||
}
|
||||
|
||||
void QgsScrollArea::resizeEvent( QResizeEvent *event )
|
||||
{
|
||||
if ( mVerticalOnly && widget() )
|
||||
widget()->setFixedWidth( event->size().width() );
|
||||
QScrollArea::resizeEvent( event );
|
||||
}
|
||||
|
||||
void QgsScrollArea::scrollOccurred()
|
||||
{
|
||||
mTimer.setSingleShot( true );
|
||||
@ -45,6 +52,16 @@ bool QgsScrollArea::hasScrolled() const
|
||||
return mTimer.isActive();
|
||||
}
|
||||
|
||||
void QgsScrollArea::setVerticalOnly( bool verticalOnly )
|
||||
{
|
||||
mVerticalOnly = verticalOnly;
|
||||
if ( mVerticalOnly )
|
||||
setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
|
||||
|
||||
if ( mVerticalOnly && widget() )
|
||||
widget()->setFixedWidth( size().width() );
|
||||
}
|
||||
|
||||
///@cond PRIVATE
|
||||
|
||||
ScrollAreaFilter::ScrollAreaFilter( QgsScrollArea *parent, QWidget *viewPort )
|
||||
|
@ -61,12 +61,25 @@ class GUI_EXPORT QgsScrollArea : public QScrollArea
|
||||
*/
|
||||
bool hasScrolled() const;
|
||||
|
||||
/**
|
||||
* Sets whether the scroll area only applies vertical.
|
||||
*
|
||||
* If set to TRUE, then scroll area children will resize horizontally to match the width of
|
||||
* the scroll area widget.
|
||||
*
|
||||
* \since QGIS 3.8
|
||||
*/
|
||||
void setVerticalOnly( bool verticalOnly );
|
||||
|
||||
protected:
|
||||
void wheelEvent( QWheelEvent *event ) override;
|
||||
void resizeEvent( QResizeEvent *event ) override;
|
||||
|
||||
private:
|
||||
QTimer mTimer;
|
||||
ScrollAreaFilter *mFilter = nullptr;
|
||||
bool mVerticalOnly = false;
|
||||
|
||||
};
|
||||
|
||||
#ifndef SIP_RUN
|
||||
|
Loading…
x
Reference in New Issue
Block a user