PyQt 中的信号和槽
过去我有过一些使用 C++ 编写 Qt 的经验。我现在开始使用 PyQt,发现它有点令人困惑。除了 Riverbank 的少量资料外,似乎没有任何明确的文档来源。我想我想知道的第一件事是 PyQt 有一个最初的驼峰,而且它确实变得更容易了。 [编辑:我遇到的主要问题是由于拼写错误 - init
而不是 __init__
。我现在没觉得那么难了 :P]
PyQt 文档谈论新样式信号和 PyQt 的插槽,以及旧样式。他们认为新的风格更好,但我想知道这是否是 PyQt 的大多数用户所做的。
In the past I've had some experience of Qt in C++. I've now started using PyQt, and finding it a bit bewildering. There doesn't seem to be any definitive source of documentation, apart from a small amount at Riverbank. I guess the first thing I'd like to know is that there's an initial hump with PyQt, and it does get easier. [Edit: The main problem I was having was due to a typo - init
not __init__
. I'm not finding it so hard now :P]
The PyQt docs talk about new style signals and slots for PyQt, as well as old style. They suggest that the new style is better, but I was wondering if that is what most users of PyQt do.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,就是这样。新的语法更加清晰,为什么不呢?
请注意,当您尝试按名称连接插槽时,您必须显式调用 connectSlotsByName,因为在执行之前没有预处理器可以工作并连接它们。
PS:此外,信号/槽连接的 C++ 语法非常丑陋,而旧的 PyQt 语法毫无理由地非常相似,所以我很高兴看到 PyQt 中的这种变化。
PS2:最近有一个关于这个的问题,你看看。
Yes, that is. New syntax is more clear, so why not?
Note, that when you trying to connect slots by name, you must call connectSlotsByName explicitly, since there no preprocessor that will work before execution and connect them.
PS: Beside, C++ syntax for signal/slot connnection is just ugly, and old PyQt syntax was pretty similar without any reason, so I was glad to see this change in PyQt.
PS2: There was the question here recently about this, check it out.
参考请参见: PyQt 类参考< /strong> - 它非常全面,并通过示例详细介绍。大多数示例都是用 C++ 编写的,虽然我是一个 Python 新手,但我并不觉得翻译成 Python 很困难。
如果您是一位经验丰富的开发人员并开始使用 Python 和 PyQt,那么这是一本相当不错的书 - 关于我所知道的关于该主题的唯一完整书籍:使用 Python 和 Qt 进行快速 GUI 编程。
信号和槽:我总是在 PyQt 中使用信号和槽的新语法,它简单而优雅 - 更加“Pythonic”。 PyQt 很棒,但在很多方面它仍然非常像 C++ - 他们对它进行“Python 化”越多越好。
For reference see: PyQt Class Reference - it's quite comprehensive and goes into details with examples. Most of the examples are in C++ and although I'm something of a Python newbee, I didn't find it difficult to translate into Python.
If you're an experienced developer and starting to use Python and PyQt, this is a pretty good book - about the only full scale book on the subject that I know of: Rapid GUI Programming with Python and Qt.
Signals and Slots: I always use the new syntax for signals and slots in PyQt, which is simple and elegant - much more 'pythonic'. PyQt is great, but in many respects it's still very C++ like - the more they do to 'pythonate' it, the better.