-
-
Notifications
You must be signed in to change notification settings - Fork 575
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed and optimized OpacityAniStackedWidget (PyQt6) #812
base: PyQt6
Are you sure you want to change the base?
Conversation
|
||
self._opacity1 = QGraphicsOpacityEffect(self) | ||
self._opacity2 = QGraphicsOpacityEffect(self) | ||
self._opacity2.setOpacity(0.0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_opacity1
is assigned to former widget whilst _opacity2
is assigned to widget that is to be shown
def setDuration(self, ms: int) -> None: | ||
"""Sets the duration of the transition between widgets""" | ||
self._opacityUp.setDuration(ms) | ||
self._opacityDown.setDuration(ms) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added method to customize duration of the transition.
@zhiyiYo What do you think about this? Is there a reason you haven't looked into this? 你怎么看待这件事? 您还有什么理由没有研究过这个问题吗? |
I've been a bit busy lately, so I'll have to wait a little longer to verify this PR |
…rldTransform while keeping behavior.
Added a small fix to avoid a problem that arises when multiple objects try to paint a view at the same time. |
Class
OpacityAniStackedWidget
presented a couple issues because it was not able to transition between widgets that had an index difference greater than 2 in the stack. Also, when transition was made, sometimes, older widgets would remain visible in the frame. Here is an example of this behavior, in which I linked key presses tosetCurrentIndex
method.Little explanation: I navigate to the "Cursos" subinterface from the window, and right below the commandBar that is shown in the frame, there is the stacked widget.
In this scenario, the book image is linked in a widget to index 0, in index 1 there is the CardWidget (with the orange square), and in index 2 there is an empty widget, it may be difficult to appreciate in this demonstration because of the incorrect behavior of the current class.
Another issue that former implementation presented was the increasing amount of memory used by the class as it creates new instances of
QGraphicsOpacityEffect
andQPropertyAnimation
for each widget in the stacked widget. Finally, stack would break the program if there was an attempt to change to an index that did not exist.I fixed all the issues described above as follows:
Here is a presentation of the new, expected, behavior:
Note that this implementation works well in PyQt6, which I am most familiar with. It would be needed that someone with experience in older versions implements this in such versions.
OpacityAniStackedWidget 类出现了一些问题,因为它无法在堆栈中索引差值大于 2 的小部件之间进行转换。 此外,当进行转换时,有时旧的小部件将在框架中保持可见。 下面是此行为的一个示例,其中我将按键链接到 setCurrentIndex 方法。
小解释:我从窗口导航到“Cursos”子界面,在框架中显示的命令栏的正下方,有堆叠的小部件。
在这种情况下,书籍图像在小部件中链接到索引 0,索引 1 中有 CardWidget(带有橙色方块),索引 2 中有一个空小部件,在本演示中可能很难理解,因为 当前类的不正确行为。
以前的实现提出的另一个问题是类使用的内存量不断增加,因为它为堆叠小部件中的每个小部件创建了“QGraphicsOpacityEffect”和“QPropertyAnimation”的新实例。 最后,如果尝试更改不存在的索引,堆栈将破坏程序。
我修复了上述所有问题,如下所示:
以下是新的预期行为的演示:
请注意,这个实现在我最熟悉的 PyQt6 中运行良好。 需要有旧版本经验的人在此类版本中实现这一点。