Skip to content
Permalink
Browse files

Allow QgsScrollArea to maintain horizontal width of area for

child widgets, and apply scroll area to vertical contents only
  • Loading branch information
nyalldawson committed May 1, 2019
1 parent 5a57336 commit ffe02c37b6c5993a410f0dc709dd80211d2414e6
Showing with 42 additions and 0 deletions.
  1. +12 −0 python/gui/auto_generated/qgsscrollarea.sip.in
  2. +17 −0 src/gui/qgsscrollarea.cpp
  3. +13 −0 src/gui/qgsscrollarea.h
@@ -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

0 comments on commit ffe02c3

Please sign in to comment.
You can’t perform that action at this time.