Fixed and optimized OpacityAniStackedWidget (PyQt6) #812
+47
−41
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 中运行良好。 需要有旧版本经验的人在此类版本中实现这一点。