summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/widgets/itemviews/qtreeview.cpp30
-rw-r--r--src/widgets/itemviews/qtreeview.h3
-rw-r--r--src/widgets/itemviews/qtreeview_p.h5
-rw-r--r--src/widgets/styles/qcommonstyle.cpp3
-rw-r--r--src/widgets/styles/qstyle.cpp3
-rw-r--r--src/widgets/styles/qstyle.h1
6 files changed, 41 insertions, 4 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
*/
diff --git a/src/widgets/itemviews/qtreeview.h b/src/widgets/itemviews/qtreeview.h
index 429b9d3add..8ac53b8bb7 100644
--- a/src/widgets/itemviews/qtreeview.h
+++ b/src/widgets/itemviews/qtreeview.h
@@ -56,7 +56,7 @@ class Q_WIDGETS_EXPORT QTreeView : public QAbstractItemView
{
Q_OBJECT
Q_PROPERTY(int autoExpandDelay READ autoExpandDelay WRITE setAutoExpandDelay)
- Q_PROPERTY(int indentation READ indentation WRITE setIndentation)
+ Q_PROPERTY(int indentation READ indentation WRITE setIndentation RESET resetIndentation)
Q_PROPERTY(bool rootIsDecorated READ rootIsDecorated WRITE setRootIsDecorated)
Q_PROPERTY(bool uniformRowHeights READ uniformRowHeights WRITE setUniformRowHeights)
Q_PROPERTY(bool itemsExpandable READ itemsExpandable WRITE setItemsExpandable)
@@ -83,6 +83,7 @@ public:
int indentation() const;
void setIndentation(int i);
+ void resetIndentation();
bool rootIsDecorated() const;
void setRootIsDecorated(bool show);
diff --git a/src/widgets/itemviews/qtreeview_p.h b/src/widgets/itemviews/qtreeview_p.h
index 5d6333e856..c44d6d7ced 100644
--- a/src/widgets/itemviews/qtreeview_p.h
+++ b/src/widgets/itemviews/qtreeview_p.h
@@ -89,7 +89,7 @@ public:
uniformRowHeights(false), rootDecoration(true),
itemsExpandable(true), sortingEnabled(false),
expandsOnDoubleClick(true),
- allColumnsShowFocus(false), current(0), spanning(false),
+ allColumnsShowFocus(false), customIndent(false), current(0), spanning(false),
animationsEnabled(false), columnResizeTimerID(0),
autoExpandDelay(-1), hoverBranch(-1), geometryRecursionBlock(false), hasRemovedItems(false),
treePosition(0) {}
@@ -191,6 +191,7 @@ public:
bool sortingEnabled;
bool expandsOnDoubleClick;
bool allColumnsShowFocus;
+ bool customIndent;
// used for drawing
mutable QPair<int,int> leftAndRight;
@@ -241,6 +242,8 @@ public:
int accessibleTree2Index(const QModelIndex &index) const;
+ void updateIndentationFromStyle();
+
// used for spanning rows
QVector<QPersistentModelIndex> spanningIndexes;
diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp
index ce6d3d708f..ec289e896b 100644
--- a/src/widgets/styles/qcommonstyle.cpp
+++ b/src/widgets/styles/qcommonstyle.cpp
@@ -4695,6 +4695,9 @@ int QCommonStyle::pixelMetric(PixelMetric m, const QStyleOption *opt, const QWid
case PM_SubMenuOverlap:
ret = -proxy()->pixelMetric(QStyle::PM_MenuPanelWidth, opt, widget);
break;
+ case PM_TreeViewIndentation:
+ ret = int(QStyleHelper::dpiScaled(20.));
+ break;
default:
ret = 0;
break;
diff --git a/src/widgets/styles/qstyle.cpp b/src/widgets/styles/qstyle.cpp
index fb5a5c9003..c3be177732 100644
--- a/src/widgets/styles/qstyle.cpp
+++ b/src/widgets/styles/qstyle.cpp
@@ -1470,6 +1470,9 @@ void QStyle::drawItemPixmap(QPainter *painter, const QRect &rect, int alignment,
\value PM_TabCloseIndicatorWidth The default width of a close button on a tab in a tab bar.
\value PM_TabCloseIndicatorHeight The default height of a close button on a tab in a tab bar.
+ \value PM_TreeViewIndentation The indentation of items in a tree view.
+ This enum value has been introduced in Qt 5.4.
+
\value PM_CustomBase Base value for custom pixel metrics. Custom
values must be greater than this value.
diff --git a/src/widgets/styles/qstyle.h b/src/widgets/styles/qstyle.h
index a2de839404..c647513dca 100644
--- a/src/widgets/styles/qstyle.h
+++ b/src/widgets/styles/qstyle.h
@@ -556,6 +556,7 @@ public:
PM_ScrollView_ScrollBarSpacing,
PM_ScrollView_ScrollBarOverlap,
PM_SubMenuOverlap,
+ PM_TreeViewIndentation,
// do not add any values below/greater than this
PM_CustomBase = 0xf0000000