QTreeWidget Extends Double-Click Animation

I created a QTreeWidget and set the animation to true ( setAnimated(true) ). When I click on a label (triangle) to the left of an element, it expands smoothly, but when I double-click on an element, it expands too quickly (almost the same as there is no β€œanimated” flag set). I want to smooth the animation with a double click. How can I solve this problem?

QTreeView calls QTreeViewPrivate::expandOrCollapseItemAtPos when the label is clicked and QTreeViewPrivate::expand when double clicked, so I do not have access to these methods.

I use PySide to create a Qt application (but I tried C ++ and the problem is the same).

+4
source share
2 answers

You need to override click behavior. Check the event if it is a double click or not, and then you can redirect the event to the appropriate call. You should check the status if it is already pressed or not to prevent a second animation that may occur.

+1
source

The trick is that double-clicking also increases one click by default. Before deploying the default animation, call QAbstractItemView::setState(AnimatingState) to set the internal state for the animation.

And in QAbstractItemView::mouseReleaseEvent() , QAbstractItemView::setState(NoState) is called before the animation finishes. After that, the animation stops immediately.

Use the following code to work:

 void YourSubTreeView::mouseReleaseEvent(QMouseEvent* event) { QAbstractItemView::State preState = state(); QTreeView::mouseReleaseEvent(event); if (preState == QAbstractItemView::AnimatingState) setState(preState); } 
0
source

Source: https://habr.com/ru/post/1445003/


All Articles