PyQt

From Wikipedia, the free encyclopedia
Jump to: navigation, search
PyQt
Python and Qt.svg
Screenshot-qt-designer-qwebview.png
Developer(s) Riverbank Computing
Stable release 5.2.1 / March 14, 2014; 32 days ago (2014-03-14)[1]
Written in C++/Python[2]
Operating system Cross-platform
License GNU GPL and commercial
Website riverbankcomputing.com

PyQt is a Python binding of the cross-platform GUI toolkit Qt. It is one of Python's options for GUI programming. Popular alternatives are PySide (the Qt binding with official support and a more liberal licence), PyGTK, wxPython, and Tkinter (which is bundled with Python). Like Qt, PyQt is free software. PyQt is implemented as a Python plug-in.

PyQt is 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 OS X.[4]

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

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,[7] after failing to reach an agreement with Riverbank Computing[8] to change its licensing terms to include LGPL as an alternative license.

Alternative PyQt logo

PyQt main components[edit]

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.[4]

Hello world example[edit]

The below code shows a small window on the screen.

The result in KDE
#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
# Here we provide the necessary imports.
# The basic GUI widgets are located in QtGui module.
import sys
from PyQt4.QtGui import *

# Every PyQt4 application must create an application object.
# The application object is located in the QtGui module.
a = QApplication(sys.argv)

# The QWidget widget is the base class of all user interface objects in PyQt4.
# We provide the default constructor for QWidget. The default constructor has no parent.
# A widget with no parent is called a window.
w = QWidget()

w.resize(320, 240)  # The resize() method resizes the widget.
w.setWindowTitle("Hello, World!")  # Here we set the title for our window.
w.show()  # The show() method displays the widget on the screen.

sys.exit(a.exec_())  # Finally, we enter the mainloop of the application.

Notable applications that use PyQt[edit]

  • Anki, a spaced repetition flashcard program
  • Eric Python IDE
  • Kodos, Python Regular Expression Debugger
  • Orange, a data mining and visualization framework
  • qt-recordMyDesktop, Qt4 frontend for recordMyDesktop
  • QGIS, a free software desktop Geographic Information Systems (GIS) application
  • Veusz, a scientific plotting application
  • Spyder, a lightweight Python IDE
  • Leo, an outliner and literate programming editor
  • Ninja-IDE, an extensible open-source Python IDE
  • Calibre, an E-book management application
  • Puddletag, an open-source, cross-platform ID3 tag editor
  • TortoiseHg, a graphical interface for the Mercurial source management program (Hg)

See also[edit]

References[edit]

  1. ^ http://www.riverbankcomputing.com/news/pyqt-521
  2. ^ "PyQt4 Download". Riverbankcomputing. 2010. Retrieved 2010-04-19. 
  3. ^ "Riverbank | Software | PyQt | License". Riverbankcomputing.co.uk. Retrieved 2009-09-03. 
  4. ^ a b "Riverbank | Software | PyQt | What is PyQt?". Riverbankcomputing.co.uk. Retrieved 2010-04-15. 
  5. ^ "PyQt v4 - Python Bindings for Qt v4". Riverbankcomputing. Retrieved 2010-04-17. 
  6. ^ PythonInfo Wiki
  7. ^ "PySide has been released – PySide – Python for Qt". Pyside.org. 2009-08-18. Retrieved 2009-09-03. 
  8. ^ "FAQ – PySide – Python for Qt". Pyside.org. Retrieved 2009-09-03. 

Further reading[edit]

External links[edit]