PyQt4 中的 Q_ENUMS

发布于 2024-12-09 14:55:41 字数 64 浏览 7 评论 0原文

我想使用 Qt 的枚举功能。我在 QtCore 模块的文档中看到有一个 Q_ENUMS 宏,但我不知道如何使用他。

I would like to use facilities of enumeration of Qt. I saw in documentation of the module of QtCore there is a macros of Q_ENUMS, but I do not know and information how to use him.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

兔小萌 2024-12-16 14:55:41

在 python(和 PyQt)中,创建枚举的方法如下:

class MyEnum(object):
    One = 1
    Two = 2
    Three = 3

如果您需要更多功能,请提供您想要执行的操作的更多详细信息。

编辑

查看QAbstractSocket.stateChanged的文档 我可以看到它指的是“创建自定义 Qt 类型”。我不知道需要在 PyQt4 中注册元类型,因此使用此信号所需要做的就是将其连接到适当的处理程序:

class Socket(QTcpSocket):
    def __init__(self):
        QTcpSocket.__init__(self)
        self.stateChanged.connect(self.handleStateChanged)

    def handleStateChanged(self, state):
        print state

In python (and PyQt), the way to create an enum is like this:

class MyEnum(object):
    One = 1
    Two = 2
    Three = 3

If you need more functionality than that, please give more details of what you are trying to do.

EDIT

Looking at the documentation for QAbstractSocket.stateChanged I can see it refers to "Creating Custom Qt Types". I am not aware of any need for registering metatypes in PyQt4, so all you need to do to use this signal is connect it to an appropriate handler:

class Socket(QTcpSocket):
    def __init__(self):
        QTcpSocket.__init__(self)
        self.stateChanged.connect(self.handleStateChanged)

    def handleStateChanged(self, state):
        print state
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文