pyqt4

Topics related to pyqt4:

Getting started with pyqt4

This section provides an overview of what PyQt4 is, and why a developer might want to use it.

PyQt is a GUI widgets toolkit. It is a Python interface for Qt, one of the most powerful, and popular cross-platform GUI library. PyQt is a blend of Python programming language and the Qt library. This introductory tutorial will assist you in creating graphical applications with the help of PyQt.

It should also mention any large subjects within PyQt4, and link out to the related topics. Since the Documentation for PyQt4 is new, you may need to create initial versions of those related topics.

Hello World Program

Creating a simple GUI application using PyQt involves the following steps −

  1. Import QtGui module

  2. Create an application object.

  3. A QWidget object creates top level window. Add QLabel object in it.

  4. Set the caption of label as “hello world”.

  5. Define the size and position of window by setGeometry() method.

  6. Enter the mainloop of application by app.exec_() method.

Signals and Slots

In the following example, two QPushButton objects (b1 and b2) are added in QDialog window. We want to call functions b1_clicked() and b2_clicked() on clicking b1 and b2 respectively.

When b1 is clicked, the clicked() signal is connected to b1_clicked() function

b1.clicked.connect(b1_clicked())

When b2 is clicked, the clicked() signal is connected to b2_clicked() function

QObject.connect(b2, SIGNAL("clicked()"), b2_clicked)

Widgets used to build the GUI interface act as the source of such events.

Each PyQt widget, which is derived from QObject class, is designed to emit signal in response to one or more events. The signal on its own does not perform any action. Instead, it is connected to a slot. The slot can be any callable Python function.

Basic Widgets : QLabel

QMessageBox