File tree Expand file tree Collapse file tree 3 files changed +42
-0
lines changed
python/gui/auto_generated Expand file tree Collapse file tree 3 files changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -45,11 +45,23 @@ QScrollArea itself or its child viewport().
4545%Docstring
4646Returns ``True`` if a scroll recently occurred within
4747the QScrollArea or its child viewport()
48+ %End
49+
50+ void setVerticalOnly( bool verticalOnly );
51+ %Docstring
52+ Sets whether the scroll area only applies vertical.
53+
54+ If set to ``True``, then scroll area children will resize horizontally to match the width of
55+ the scroll area widget.
56+
57+ .. versionadded:: 3.8
4858%End
4959
5060 protected:
5161 virtual void wheelEvent( QWheelEvent *event );
5262
63+ virtual void resizeEvent( QResizeEvent *event );
64+
5365
5466};
5567
Original file line number Diff line number Diff line change @@ -34,6 +34,13 @@ void QgsScrollArea::wheelEvent( QWheelEvent *e )
3434 QScrollArea::wheelEvent ( e );
3535}
3636
37+ void QgsScrollArea::resizeEvent ( QResizeEvent *event )
38+ {
39+ if ( mVerticalOnly && widget () )
40+ widget ()->setFixedWidth ( event->size ().width () );
41+ QScrollArea::resizeEvent ( event );
42+ }
43+
3744void QgsScrollArea::scrollOccurred ()
3845{
3946 mTimer .setSingleShot ( true );
@@ -45,6 +52,16 @@ bool QgsScrollArea::hasScrolled() const
4552 return mTimer .isActive ();
4653}
4754
55+ void QgsScrollArea::setVerticalOnly ( bool verticalOnly )
56+ {
57+ mVerticalOnly = verticalOnly;
58+ if ( mVerticalOnly )
59+ setHorizontalScrollBarPolicy ( Qt::ScrollBarAlwaysOff );
60+
61+ if ( mVerticalOnly && widget () )
62+ widget ()->setFixedWidth ( size ().width () );
63+ }
64+
4865// /@cond PRIVATE
4966
5067ScrollAreaFilter::ScrollAreaFilter ( QgsScrollArea *parent, QWidget *viewPort )
Original file line number Diff line number Diff line change @@ -61,12 +61,25 @@ class GUI_EXPORT QgsScrollArea : public QScrollArea
6161 */
6262 bool hasScrolled () const ;
6363
64+ /* *
65+ * Sets whether the scroll area only applies vertical.
66+ *
67+ * If set to TRUE, then scroll area children will resize horizontally to match the width of
68+ * the scroll area widget.
69+ *
70+ * \since QGIS 3.8
71+ */
72+ void setVerticalOnly ( bool verticalOnly );
73+
6474 protected:
6575 void wheelEvent ( QWheelEvent *event ) override ;
76+ void resizeEvent ( QResizeEvent *event ) override ;
6677
6778 private:
6879 QTimer mTimer ;
6980 ScrollAreaFilter *mFilter = nullptr ;
81+ bool mVerticalOnly = false ;
82+
7083};
7184
7285#ifndef SIP_RUN
You can’t perform that action at this time.
0 commit comments