类、方法和模块的 PyQt5 文档在哪里? [英] Where is the PyQt5 documentation for classes, methods and modules?

查看:24
本文介绍了类、方法和模块的 PyQt5 文档在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试学习 PyQt5,但我发现它非常困难,因为我无法猜测有哪些方法可用.我刚刚花了整整一周的时间试图找到一种模拟按钮按下的方法.我最终发现了解决方案( QPushButton.animateClick() ),只是在偶然发现有人遗漏的一个例子(这个人怎么知道这个?).如果不参考可用于工具的内容,开发将非常困难!Riverbank 有一个我正在寻找的版本,但它并不完整,几乎没有用处.

解决方案

此表指示如何在 C++ 项目中包含该类,如何将其添加到 qmake,它从哪个类继承,以及哪些类从它继承.从上面可以提取出PyQt5的相关信息,例如该类属于哪个子模块:在这种情况下,我们使用QT += widgets告诉我们它属于QtWidgets 子模块,一般如果 Qt += submodulefoo 属于 QtSubModuleFoo (camelcase)

如果你想知道QPushButton类的所有方法,你必须使用表格下方的所有成员列表,包括继承的成员"链接,此时链接为https://doc.qt.io/qt-5/qpushbutton-members.html 其中是所有类方法、枚举等的完整列表.

了解 Qt/C++ 和 PyQt5/Python 之间转换的其他提示是:

  1. 有些方法使用指针来接收信息,例如:

    那些转换为 PyQt5 的:

    lay = QtWidgets.QXLayout()左、上、右、下 =lay.getContentsMargins()

    process = QProcess()# ...好的,pid = process.startDetached()

  2. 有些方法与保留字如 execraiseprint 等有冲突,为避免不兼容,下划线为在末尾添加:exec_raise_print_

  3. 在 Qt 中,Q_SLOT 和 Q_SIGNAL 被翻译成python 通过 @pyqtSlot 和 @pyqtSignal 装饰器使用.

<小时>

总之,我的建议是您同时使用 Qt 和 PyQt5 文档来了解所有功能,此外,SO 中有许多关于从一种语言翻译成另一种语言的问答,因此您可以从中学习.

也可以使用 Qt Assistant 查阅 Qt 文档 工具.

I'm trying to learn PyQt5 and I am finding it very difficult since I can't just guess what methods are available. I've just spent an entire week trying to find a method to simulate a button push. I eventually found the solution ( QPushButton.animateClick() ) only after stumbling across an example someone left out there (how did this person know this?). It's very difficult to develop without some reference to what's available for tools! Riverbank has a version of what I'm looking for but it is not complete making it virtually useless.

解决方案

being a binding has almost all the functionalities (there are minimal known incompatibilities) so the documentation: https://doc.qt.io/ is valid for except for small exceptions.

Although the target of the documentation is the description of the classes and methods are generic, so they also validly apply for , on the other hand many of the examples are written in but the translation to python in many cases is trivial .

So to avoid doing a double task it seems that Riverbank Computing Limited only documents the exceptions indicated in the docs: https://www.riverbankcomputing.com/static/Docs/PyQt5/


The next part of my answer will propose tips to handle the Qt documentation.

The Qt documentation also has an easy to understand structure, for example let's analyze the QPushButton class (https://doc.qt.io/qt-5/qpushbutton.html):

At the top there is a table:

This table indicates how to include the class in a C++ project, how to add it to qmake, from which class it inherits, and which classes inherit from it. From the above, relevant information for PyQt5 can be extracted, such as to which sub-module the class belongs to: In this case we use QT += widgets that inform us that it belongs to the QtWidgets sub-module, in general if Qt += submodulefoo belongs to QtSubModuleFoo (camelcase)

If you want to know all the methods of the QPushButton class, you must use the "List of all members, including inherited members" link below the table, in this case the link will be https://doc.qt.io/qt-5/qpushbutton-members.html where is the complete list of all class methods, enumerations, etc.

Other tips to understand the conversion between Qt/C++ and PyQt5/Python are:

  1. Some methods use pointers to receive information such as:

    those transformed to PyQt5 as:

    lay = QtWidgets.QXLayout()
    left, top, right, bottom = lay.getContentsMargins()
    

    process = QProcess()
    # ...
    ok, pid = process.startDetached()
    

  2. Some methods collide with reserved words such as exec , raise, print, etc so to avoid incompatibilities, the underscore is added at the end: exec_, raise_, print_, etc

  3. In Qt, the Q_SLOT and Q_SIGNAL that are translated into python are used through the @pyqtSlot and @pyqtSignal decorators.


In conclusion, my recommendation is that you use the Qt and PyQt5 documentation at the same time to know all the functionalities, in addition there are many Q&A in SO about translations from one language to another so you could learn from there.

The Qt documentation can also be consulted using the Qt Assistant tool.

这篇关于类、方法和模块的 PyQt5 文档在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆