summaryrefslogtreecommitdiffstats
path: root/src/widgets/itemviews/qtreeview.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/itemviews/qtreeview.cpp')
-rw-r--r--src/widgets/itemviews/qtreeview.cpp30
1 files changed, 28 insertions, 2 deletions
diff --git a/src/widgets/itemviews/qtreeview.cpp b/src/widgets/itemviews/qtreeview.cpp
index 3f952ff768..ae3994e30a 100644
--- a/src/widgets/itemviews/qtreeview.cpp
+++ b/src/widgets/itemviews/qtreeview.cpp
@@ -371,7 +371,9 @@ void QTreeView::setAutoExpandDelay(int delay)
horizontal distance from the viewport edge to the items in the first column;
for child items, it specifies their indentation from their parent items.
- By default, this property has a value of 20.
+ By default, the value of this property is style dependent. Thus, when the style
+ changes, this property updates from it. Calling setIndentation() stops the updates,
+ calling resetIndentation() will restore default behavior.
*/
int QTreeView::indentation() const
{
@@ -382,12 +384,22 @@ int QTreeView::indentation() const
void QTreeView::setIndentation(int i)
{
Q_D(QTreeView);
- if (i != d->indent) {
+ if (!d->customIndent || (i != d->indent)) {
d->indent = i;
+ d->customIndent = true;
d->viewport->update();
}
}
+void QTreeView::resetIndentation()
+{
+ Q_D(QTreeView);
+ if (d->customIndent) {
+ d->updateIndentationFromStyle();
+ d->customIndent = false;
+ }
+}
+
/*!
\property QTreeView::rootIsDecorated
\brief whether to show controls for expanding and collapsing top-level items
@@ -2081,6 +2093,12 @@ QModelIndex QTreeView::indexBelow(const QModelIndex &index) const
void QTreeView::doItemsLayout()
{
Q_D(QTreeView);
+ if (!d->customIndent) {
+ // ### Qt 6: move to event()
+ // QAbstractItemView calls this method in case of a style change,
+ // so update the indentation here if it wasn't set manually.
+ d->updateIndentationFromStyle();
+ }
if (d->hasRemovedItems) {
//clean the QSet that may contains old (and this invalid) indexes
d->hasRemovedItems = false;
@@ -3025,6 +3043,8 @@ bool QTreeView::isIndexHidden(const QModelIndex &index) const
void QTreeViewPrivate::initialize()
{
Q_Q(QTreeView);
+
+ updateIndentationFromStyle();
updateStyledFrameWidths();
q->setSelectionBehavior(QAbstractItemView::SelectRows);
q->setSelectionMode(QAbstractItemView::SingleSelection);
@@ -3911,6 +3931,12 @@ int QTreeViewPrivate::accessibleTree2Index(const QModelIndex &index) const
return (q->visualIndex(index) + (q->header() ? 1 : 0)) * index.model()->columnCount() + index.column();
}
+void QTreeViewPrivate::updateIndentationFromStyle()
+{
+ Q_Q(const QTreeView);
+ indent = q->style()->pixelMetric(QStyle::PM_TreeViewIndentation, 0, q);
+}
+
/*!
\reimp
*/