首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PyQt6 QVariantAnimation在Cython细胞化后改变动画值时不会发出valueChanged信号

PyQt6 QVariantAnimation在Cython细胞化后改变动画值时不会发出valueChanged信号
EN

Stack Overflow用户
提问于 2022-10-29 11:56:45
回答 1查看 75关注 0票数 0

当我在cythonize之前运行程序时,所有的纯.py文件都按其应有的方式工作,当动画值发生变化时,会调用连接到valueChanged的方法。但是,在我构建了cythonize之后,程序从.pyd扩展运行,连接到valueChanged信号的方法永远不会被调用。

虽然我用QVariantAnimation完成的信号检查了相同的东西,并且调用了它,但是所有的事情都正常工作,这是valueChanged的问题所在。

Python : 3.11 PyQt6版本:6.4.0Cython版本:3.0.0a11OS:Windows11

下面是一个示例,说明它在代码中的外观:

代码语言:javascript
复制
from PyQt6.QtCore import QAbstractAnimation, QVariant, QVariantAnimation, pyqtSlot
from PyQt6.QtWidgets import QHBoxLayout, QPushButton, QWidget


class SampleWidget(QWidget):
    def __init__(self, parent: QWidget | None = None) -> None:
        super().__init__(parent)
        horizontal_layout = QHBoxLayout()
        horizontal_layout.setContentsMargins(0, 0, 0, 0)
        horizontal_layout.setSpacing(0)

        self.button = QPushButton(self)
        self.button.setText("Start animation")
        self.button.clicked.connect(lambda: self.start_animation(180))
        horizontal_layout.addWidget(self.button)

        self.setLayout(horizontal_layout)

    def start_animation(self, value: float) -> None:
        self._animation = QVariantAnimation(self)
        self._animation.setStartValue(0)
        self._animation.setEndValue(value)
        self._animation.setDuration(400)
        self._animation.valueChanged.connect(self._on_animation_value_changed)
        self._animation.finished.connect(self._on_animation_finished)
        self._animation.start(QAbstractAnimation.DeletionPolicy.DeleteWhenStopped)

    @pyqtSlot()
    def _on_animation_finished(self) -> None:
        # This executes as it should be after cythonize.
        print("Animation finished")

    @pyqtSlot(QVariant)
    def _on_animation_value_changed(self, value: float) -> None:
        # Here is problem. This is never executes after cythonize.
        print("Animation value changed to", value)

和细胞化功能:

代码语言:javascript
复制
...

cythonize(
        module_list=extension_modules,
        # Don't build in source tree (this leaves behind .c files)
        build_dir=BUILD_DIR,
        # Don't generate an .html output file. This will contain source.
        annotate=False,
        # Tell Cython we're using Python 3
        compiler_directives={"language_level": "3", "always_allow_keywords": True},
        # (Optional) Always rebuild, even if files untouched
        force=True,
    )

...
EN

回答 1

Stack Overflow用户

发布于 2022-10-29 15:43:20

我将value的类型注释设置为float,虽然Qt发送int,但由于使用了错误的注释,因此发生了冲突。

非常感谢大家的回答和解释,我非常感谢你们!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74245047

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档