PyQt

PyQt is a Python binding of the cross-platform GUI toolkit Qt, implemented as a Python plug-in. PyQt is free software developed by the British firm Riverbank Computing. It is available under similar terms to Qt versions older than 4.5; this means a variety of licenses including GNU General Public License (GPL) and commercial license, but not the GNU Lesser General Public License (LGPL).[3] PyQt supports Microsoft Windows as well as various flavours of UNIX, including Linux and MacOS (or Darwin).[4]

PyQt
Qt Designer
Developer(s)Riverbank Computing
Stable release
5.15.0 / June 1, 2020 (2020-06-01)[1]
Written inC++ / Python[2]
Operating systemCross-platform
LicenseGNU GPL and commercial
Websiteriverbankcomputing.com

PyQt implements around 440 classes and over 6,000 functions and methods[5] including:

  • a substantial set of GUI widgets
  • classes for accessing SQL databases (ODBC, MySQL, PostgreSQL, Oracle, SQLite)[6]
  • QScintilla, Scintilla-based rich text editor widget
  • data aware widgets that are automatically populated from a database
  • an XML parser
  • SVG support
  • classes for embedding ActiveX controls on Windows (only in commercial version)[7]

To automatically generate these bindings, Phil Thompson developed the tool SIP, which is also used in other projects.

In August 2009, Nokia, the then owners of the Qt toolkit, released PySide, providing similar functionality, but under the LGPL,[8] after failing to reach an agreement with Riverbank Computing[9] to change its licensing terms to include LGPL as an alternative license.

Alternative PyQt logo

PyQt main components

PyQt4 contains the following Python modules.

  • The QtCore module contains the core non-GUI classes, including the event loop and Qt's signal and slot mechanism. It also includes platform independent abstractions for Unicode, threads, mapped files, shared memory, regular expressions, and user and application settings.
  • The QtGui module contains the majority of the GUI classes. These include a number of table, tree and list classes based on the model–view–controller design pattern. Also provided is a sophisticated 2D canvas widget capable of storing thousands of items including ordinary widgets.
  • The QtNetwork module contains classes for writing UDP and TCP clients and servers. It includes classes that implement FTP and HTTP clients and support DNS lookups. Network events are integrated with the event loop making it very easy to develop networked applications.
  • The QtOpenGL module contains classes that enable the use of OpenGL in rendering 3D graphics in PyQt applications.
  • The QtSql module contains classes that integrate with open-source and proprietary SQL databases. It includes editable data models for database tables that can be used with GUI classes. It also includes an implementation of SQLite.
  • The QtSvg module contains classes for displaying the contents of SVG files. It supports the static features of SVG 1.2 Tiny.
  • The QtXml module implements SAX and DOM interfaces to Qt's XML parser.
  • The QtMultimedia module implements low-level multimedia functionality. Application developers would normally use the phonon module.
  • The QtDesigner module contains classes that allow Qt Designer to be extended using PyQt.
  • The Qt module consolidates the classes contained in all of the modules described above into a single module. This has the advantage that you don't have to worry about which underlying module contains a particular class. It has the disadvantage that it loads the whole of the Qt framework, thereby increasing the memory footprint of an application. Whether you use this consolidated module, or the individual component modules is down to personal taste.
  • The uic module implements support for handling the XML files created by Qt Designer that describe the whole or part of a graphical user interface. It includes classes that load an XML file and render it directly, and classes that generate Python code from an XML file for later execution.[10]

PyQt5 contains the following Python modules:

  • QtQml Module
  • QtQtuick Module
  • QtCore Module
  • QtGui Module
  • QtPrintSupport Module
  • QtWidgets Module
  • QGLContext Module
  • QGLFormat Module
  • QGLWidget Module
  • QtWebKit Module
  • QtWebKitWidgets Module

Versions

PyQt version 4 works with both Qt 4 and Qt 5. PyQt version 5 only supports Qt version 5,[4] and drops support for features that are deprecated in Qt 5.[11]

Hello World example

The below code shows a small window on the screen.

PyQt4

The result in KDE Plasma 4
 1 #! /usr/bin/env python3
 2 # Character Encoding: UTF-8
 3 #
 4 # Here we provide the necessary imports.
 5 # The basic GUI widgets are located in QtGui module. 
 6 import sys
 7 from PyQt4.QtGui import QApplication, QWidget
 8 
 9 # Every PyQt4 application must create an application object.
10 # The application object is located in the QtGui module.
11 app = QApplication(sys.argv)
12 
13 # The QWidget widget is the base class of all user interface objects in PyQt4.
14 # We provide the default constructor for QWidget. The default constructor has no parent.
15 # A widget with no parent is called a window. 
16 root = QWidget()
17 
18 root.resize(320, 240)  # The resize() method resizes the widget.
19 root.setWindowTitle("Hello, World!")  # Here we set the title for our window.
20 root.show()  # The show() method displays the widget on the screen.
21 
22 sys.exit(app.exec_())  # Finally, we enter the mainloop of the application.

PyQt5

 1 #! /usr/bin/env python3
 2 # Character Encoding: UTF-8
 3 #
 4 # Here we provide the necessary imports.
 5 # The basic GUI widgets are located in QtWidgets module. 
 6 import sys
 7 from PyQt5.QtWidgets import QApplication, QWidget
 8 
 9 # Every PyQt5 application must create an application object.
10 # The application object is located in the QtWidgets module.
11 app = QApplication(sys.argv)
12 
13 # The QWidget widget is the base class of all user interface objects in PyQt5.
14 # We provide the default constructor for QWidget. The default constructor has no parent.
15 # A widget with no parent is called a window. 
16 root = QWidget()
17 
18 root.resize(320, 240)  # The resize() method resizes the widget.
19 root.setWindowTitle("Hello, World!")  # Here we set the title for our window.
20 root.show()  # The show() method displays the widget on the screen.
21 
22 sys.exit(app.exec_())  # Finally, we enter the mainloop of the application.

Notable applications that use PyQt

  • Anki, a spaced repetition flashcard program
  • Calibre, an E-book management application
  • Dropbox, a file hosting service
  • Eric Python IDE
  • fman, cross-platform file manager
  • Kodos, Python Regular Expression Debugger
  • Leo, an outliner and literate programming editor
  • Ninja-IDE, an extensible open-source Python IDE
  • OpenLP, an open-source lyrics projection program
  • OpenShot, a video editing program
  • Orange, a data mining and visualization framework
  • Puddletag, an open-source, cross-platform ID3 tag editor
  • QGIS, a free software desktop Geographic Information Systems (GIS) application
  • qt-recordMyDesktop, Qt4 frontend for recordMyDesktop
  • Spyder, a Python data science IDE
  • TortoiseHg, a graphical interface for the Mercurial source management program (Hg)
  • Veusz, a scientific plotting application
gollark: Commands:- play- potato- error
gollark: Command invalid.
gollark: Error: potato
gollark: Error: "rick roll" not found.
gollark: g!?

See also

PyQt is one of Python's options for GUI programming. Popular alternatives are PySide (the Qt binding with official support and a more liberal license), PyGTK, wxPython, Kivy and Tkinter (which is bundled with Python).

References

  1. https://pypi.org/project/PyQt5/#history
  2. "PyQt4 Download". Riverbankcomputing. 2010. Retrieved 2010-04-19.
  3. "Riverbank | Commercial | License FAQ". Riverbankcomputing.com. Retrieved 2015-06-24.
  4. "What is PyQt?". Riverbank Computing. Retrieved 2014-09-18.
  5. "PyQt v4 - Python Bindings for Qt v4". Riverbankcomputing. Archived from the original on 2008-04-29. Retrieved 2010-04-17.
  6. "QSqlDatabase Class Reference". Pyqt.sourceforge.net. Retrieved 2014-09-25.
  7. PythonInfo Wiki
  8. "PySide has been released – PySide – Python for Qt". Pyside.org. 2009-08-18. Archived from the original on 2009-10-25. Retrieved 2009-09-03.
  9. "FAQ – PySide – Python for Qt". Pyside.org. Retrieved 2009-09-03.
  10. "Riverbank | Software | PyQt | What is PyQt?". Riverbankcomputing.co.uk. Retrieved 2010-04-15.
  11. "Differences Between PyQt4 and PyQt5", PyQt 5.3.2 Reference Guide

Further reading

This article is issued from Wikipedia. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.