QTreeWidget 双击展开动画 [英] QTreeWidget expand animation on double click
问题描述
我创建了一个 QTreeWidget
并将动画设置为 true (setAnimated(true)
).当我单击项目左侧的标记(三角形)时,它会平滑扩展,但是当我双击该项目时,它会扩展得太快(几乎就像没有设置动画"标志一样).我也想双击流畅的动画.我该如何解决这个问题?
I have created a QTreeWidget
and set animation to true (setAnimated(true)
).
When I'm clicking on a mark (triangle) at the left of item it expands smoothly, but when I'm double clicking on the item it expands too fast (almost like there is no "animated" flag set).
I want smooth animation on double click too. How can I solve this problem?
QTreeView
在标记单击时调用 QTreeViewPrivate::expandOrCollapseItemAtPos
并在双击时调用 QTreeViewPrivate::expand
,所以我无法访问这些方法.
QTreeView
calls QTreeViewPrivate::expandOrCollapseItemAtPos
on mark click and QTreeViewPrivate::expand
on double click, so I have no access to these methods.
我正在使用 PySide 创建 Qt 应用程序(但我尝试过 C++ 并且问题是相同的).
I'm using PySide for creating Qt application (but I've tried C++ and the problem is the same).
推荐答案
您需要覆盖点击行为.检查事件是否是双击,然后您可以将事件重定向到适当的调用.您应该检查状态是否已经被点击,以防止可能发生的第二个动画.
You need to override the click behaviour. Check the event if it's a double click or not and then you can redirect the event to the appropriate call. You should check the state if it's already clicked or not to prevent a second animation which might happen.
这篇关于QTreeWidget 双击展开动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!