summaryrefslogtreecommitdiffstats
path: root/src/widgets/itemviews/qlistview.cpp
diff options
context:
space:
mode:
authorAlexander Volkov <a.volkov@rusbitech.ru>2016-10-18 16:35:16 +0300
committerAlexander Volkov <a.volkov@rusbitech.ru>2017-01-12 17:54:52 +0000
commita4c25c020554527aa9ff9b533afabffef46be131 (patch)
tree343109f81aa8eec74eba69700a3e842b6551c7e9 /src/widgets/itemviews/qlistview.cpp
parentdcec1420ea9d7e90bbd7f37be15d8e61eaf35d23 (diff)
Add expandingListItems property to QListView
This property allows to change the default behavior in which list items occupy the entire width of the column. Setting it to false will reduce their widths to the minimum values, thus allowing to have intermediate free space. Then the user will be able to begin selections by mouse from this space. [ChangeLog][QtWidgets][QListView] Added expandingListItems property. Change-Id: I6bd1b147fd0335324310a165104c36f6b0d6ac9f Task-number: QTBUG-56606 Reviewed-by: Anton Kudryavtsev <antkudr@mail.ru> Reviewed-by: Thorbjørn Lund Martsum <tmartsum@gmail.com>
Diffstat (limited to 'src/widgets/itemviews/qlistview.cpp')
-rw-r--r--src/widgets/itemviews/qlistview.cpp44
1 files changed, 40 insertions, 4 deletions
diff --git a/src/widgets/itemviews/qlistview.cpp b/src/widgets/itemviews/qlistview.cpp
index d19e5d9a9f..5224a13456 100644
--- a/src/widgets/itemviews/qlistview.cpp
+++ b/src/widgets/itemviews/qlistview.cpp
@@ -1625,6 +1625,33 @@ bool QListView::isSelectionRectVisible() const
}
/*!
+ \property QListView::expandingListItems
+ \brief if items occupy the entire width of the column
+ \since 5.9
+
+ If this property is \c true then all items in the column
+ will have the width of the column; otherwise the width of
+ each item will be determined by it's size hint.
+
+ By default, this property is \c true.
+*/
+void QListView::setExpandingListItems(bool enable)
+{
+ Q_D(QListView);
+ if (d->expandingListItems == enable)
+ return;
+ d->expandingListItems = enable;
+ if (viewMode() == ListMode && flow() == QListView::TopToBottom && isWrapping())
+ d->doDelayedItemsLayout();
+}
+
+bool QListView::isExpandingListItems() const
+{
+ Q_D(const QListView);
+ return d->expandingListItems;
+}
+
+/*!
\reimp
*/
bool QListView::event(QEvent *e)
@@ -1650,7 +1677,8 @@ QListViewPrivate::QListViewPrivate()
column(0),
uniformItemSizes(false),
batchSize(100),
- showElasticBand(false)
+ showElasticBand(false),
+ expandingListItems(true)
{
}
@@ -2365,7 +2393,8 @@ QListViewItem QListModeViewBase::indexToListViewItem(const QModelIndex &index) c
int right = (segment + 1 >= segmentPositions.count()
? contentsSize.width()
: segmentPositions.at(segment + 1));
- size.setWidth(right - pos.x());
+ size.setWidth(dd->expandingListItems ? right - pos.x()
+ : qMin(size.width(), right - pos.x()));
} else { // make the items as wide as the viewport
size.setWidth(qMax(size.width(), viewport()->width() - 2 * spacing()));
}
@@ -2551,8 +2580,15 @@ QVector<QModelIndex> QListModeViewBase::intersectingSet(const QRect &area) const
if (isHidden(row))
continue;
QModelIndex index = modelIndex(row);
- if (index.isValid())
- ret += index;
+ if (index.isValid()) {
+ if (flow() == QListView::LeftToRight || dd->expandingListItems) {
+ ret += index;
+ } else {
+ const int iw = indexToListViewItem(index).width(); // item width
+ if (iw > 0 && segStartPosition - segmentPositions.at(seg) < iw)
+ ret += index;
+ }
+ }
#if 0 // for debugging
else
qWarning("intersectingSet: row %d was invalid", row);