You can set a QTreeWidget
to animated with:
tree_widget = QtWidgets.QTreeWidget()
tree_widget.setAnimated(True)
This will make the QTreeWidgetItems
animate while they collapse and expand.
Is there a way to access and edit the animation speed, and type, in the same way you would a QtCore.QVariantAnimation()
?
I would like to be able to change the speed and animation type (eg, QtCore.QEasingCurve.Linear
) if possible.
Let's track the source;
animated
property we can find out it is actually part of QTreeView class.animationsEnabled
flag.W A R N I N G
This file is not part of the Qt API. It exists purely as an implementation detail. This header file may change from version to version without notice, or even be removed.
We mean it.
So, I don't see a direct way to access or change it without touching and building source.
I recently came across to a widget-animation-duration
property in Qt Style Sheet Reference to override built-in animation duration values with style sheets and decided to append it here. However, which widgets are supported is poorly documented. Fortunately, I was able to find related commit with help of google hacking:
"widget-animation-duration" inurl:"code.qt.io"
Diffstat
-rw-r--r-- src/widgets/doc/snippets/code/doc_src_stylesheet.qdoc 4
-rw-r--r-- src/widgets/doc/src/widgets-and-layouts/stylesheet.qdoc 16
-rw-r--r-- src/widgets/itemviews/qcolumnview.cpp 6
-rw-r--r-- src/widgets/itemviews/qtreeview.cpp 2
-rw-r--r-- src/widgets/styles/qcommonstyle.cpp 5
-rw-r--r-- src/widgets/styles/qstyle.cpp 9
-rw-r--r-- src/widgets/styles/qstyle.h 1
-rw-r--r-- src/widgets/styles/qstylesheetstyle.cpp 4
-rw-r--r-- src/widgets/widgets/qtabbar_p.h 2
-rw-r--r-- src/widgets/widgets/qwidgetanimator.cpp 4
10 files changed, 41 insertions, 12 deletions
QColumnView and QWidgetAnimator classes has these lines and I was able to change duration of QColumnView animations when I tested.
if (const int animationDuration = style()->styleHint(QStyle::SH_Widget_Animation_Duration, 0, this)) {
d->currentAnimation.setDuration(animationDuration);
BUT: QTreeView implementation only checks the flags existence but not using it's value yet because they animate it by rendering tree to pixmap and drawing it by pixels. We can assume they'll use it because this looks like a preparation for it:
animationsEnabled = q->style()->styleHint(QStyle::SH_Widget_Animation_Duration, 0, q) > 0;