diff --git a/dist/changes-5.2.0 b/dist/changes-5.2.0 index ae0d785aab..b0446fbbaf 100644 --- a/dist/changes-5.2.0 +++ b/dist/changes-5.2.0 @@ -34,8 +34,12 @@ QtWidgets --------- - QAbstractScrollArea now has a SizeAdjustPolicy. If it is set to AdjustToContents - it will make use of the new protected viewportSizeHint() (binary compatible since it - was reserved in Qt5). This function returns a suggested size based on contents. + it will make use of the protected viewportSizeHint() virtual function. This + function returns a suggested size based on contents. Note that although the + viewportSizeHint() virtual function was reserved in 5.0, user code was not + supposed to be overriding it (as the function was private and undocumented). + Code that was overriding viewportSizeHint() needs to be recompiled against 5.2 + for this feature to work correctly. - QTreeView now has setTreePosition to allow the treestructure to show data from other columns than logicalindex zero. diff --git a/src/widgets/itemviews/qabstractitemview.cpp b/src/widgets/itemviews/qabstractitemview.cpp index fd704e479b..7edad74f54 100644 --- a/src/widgets/itemviews/qabstractitemview.cpp +++ b/src/widgets/itemviews/qabstractitemview.cpp @@ -1390,6 +1390,15 @@ bool QAbstractItemView::showDropIndicator() const return d->showDropIndicator; } +/*! + \since 5.2 + \reimp +*/ +QSize QAbstractItemView::viewportSizeHint() const +{ + return QAbstractScrollArea::viewportSizeHint(); +} + /*! \property QAbstractItemView::dragEnabled \brief whether the view supports dragging of its own items diff --git a/src/widgets/itemviews/qabstractitemview.h b/src/widgets/itemviews/qabstractitemview.h index 96428515ae..4f9cd7b1c6 100644 --- a/src/widgets/itemviews/qabstractitemview.h +++ b/src/widgets/itemviews/qabstractitemview.h @@ -346,6 +346,8 @@ protected: DropIndicatorPosition dropIndicatorPosition() const; #endif + QSize viewportSizeHint() const Q_DECL_OVERRIDE; + private: Q_DECLARE_PRIVATE(QAbstractItemView) Q_DISABLE_COPY(QAbstractItemView) diff --git a/src/widgets/itemviews/qlistview.cpp b/src/widgets/itemviews/qlistview.cpp index 616a832b88..0cca52daa2 100644 --- a/src/widgets/itemviews/qlistview.cpp +++ b/src/widgets/itemviews/qlistview.cpp @@ -3200,6 +3200,16 @@ int QListView::visualIndex(const QModelIndex &index) const return visualIndex; } + +/*! + \since 5.2 + \reimp +*/ +QSize QListView::viewportSizeHint() const +{ + return QAbstractItemView::viewportSizeHint(); +} + QT_END_NAMESPACE #endif // QT_NO_LISTVIEW diff --git a/src/widgets/itemviews/qlistview.h b/src/widgets/itemviews/qlistview.h index e4ae2d03fd..a973dfb221 100644 --- a/src/widgets/itemviews/qlistview.h +++ b/src/widgets/itemviews/qlistview.h @@ -180,6 +180,8 @@ protected: void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected); void currentChanged(const QModelIndex ¤t, const QModelIndex &previous); + QSize viewportSizeHint() const Q_DECL_OVERRIDE; + private: int visualIndex(const QModelIndex &index) const; diff --git a/src/widgets/itemviews/qtableview.h b/src/widgets/itemviews/qtableview.h index db956480d6..387d24c608 100644 --- a/src/widgets/itemviews/qtableview.h +++ b/src/widgets/itemviews/qtableview.h @@ -118,8 +118,6 @@ public: void sortByColumn(int column, Qt::SortOrder order); - QSize viewportSizeHint() const; - public Q_SLOTS: void selectRow(int row); void selectColumn(int column); @@ -161,6 +159,8 @@ protected: void updateGeometries(); + QSize viewportSizeHint() const Q_DECL_OVERRIDE; + int sizeHintForRow(int row) const; int sizeHintForColumn(int column) const; diff --git a/src/widgets/itemviews/qtreeview.h b/src/widgets/itemviews/qtreeview.h index d9c6cd9269..429b9d3add 100644 --- a/src/widgets/itemviews/qtreeview.h +++ b/src/widgets/itemviews/qtreeview.h @@ -147,8 +147,6 @@ public: void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector &roles = QVector()); void selectAll(); - QSize viewportSizeHint() const; - Q_SIGNALS: void expanded(const QModelIndex &index); void collapsed(const QModelIndex &index); @@ -208,6 +206,8 @@ protected: void updateGeometries(); + QSize viewportSizeHint() const Q_DECL_OVERRIDE; + int sizeHintForColumn(int column) const; int indexRowSizeHint(const QModelIndex &index) const; int rowHeight(const QModelIndex &index) const; diff --git a/src/widgets/widgets/qscrollarea.h b/src/widgets/widgets/qscrollarea.h index 70af5fbbd7..db1083f122 100644 --- a/src/widgets/widgets/qscrollarea.h +++ b/src/widgets/widgets/qscrollarea.h @@ -69,7 +69,6 @@ public: void setWidgetResizable(bool resizable); QSize sizeHint() const; - QSize viewportSizeHint() const; bool focusNextPrevChild(bool next); @@ -86,6 +85,8 @@ protected: void resizeEvent(QResizeEvent *); void scrollContentsBy(int dx, int dy); + QSize viewportSizeHint() const Q_DECL_OVERRIDE; + private: Q_DECLARE_PRIVATE(QScrollArea) Q_DISABLE_COPY(QScrollArea)