How to create GUI apps in Python Using Qt Designer

author-image
CIOL Bureau
Updated On
New Update

BANGALORE, INDIA: I assume that you have Python interpreter and PyQt installed on your machine. Download PyQt from the http://www.riverbankcomputing.co.uk/software/ pyqt/download location. Just double click the downloaded file to begin installation.

Advertisment

publive-imageThough we can write PyQt program from scratch using a simple text editor, we can use the Qt Designer that comes with PyQt. For developing GUI applications in PyQt, using Qt designer is a quick and easy way to design user interfaces without writing a single line of code.

On opening the QT Designer, the first screen asks us to select the template for the new application. Qt Designer provides a number of templates that are suitable for different kinds of applications. We can choose any one of these templates followed by Create button. Let us select Main Window for our application. A GUI application may either consist of a main window with several dialogs or of just dialogs.

A small GUI application usually consists of at least one dialog. A Dialog application contains some buttons. It doesn't contains menu bar, toolbar, status bar or central widget whereas, a main window application normally have a menu bar, toolbars, status bar, buttons and a central widget. A central widget is a widget that contains other widgets.

Advertisment

Qt Designer displays a menu bar and toolbar at the top. Besides this, the Qt Designer shows a Widget Toolbox on its left that contains varieties of widgets required in developing applications. The widgets are grouped into sections.

All, we have to do is to drag and drop desired widgets from the respective sections on the form. We can set their appearance through Property Window on the right. The user interface that we create through Qt designer is stored in a .ui file that is an XML file. To use the XML file created by Qt Designer, we need to convert it into Python code. We will soon see the method of converting .ui files into python code.

On the right side, in the Qt Designer we will find three windows:

Advertisment

Object Inspector - It displays a hierarchical list of all the objects that are present on the form. We can select any object on a form by clicking on its corresponding name in the Object Inspector. Usually, we select an object in Object Inspector window when we have overlapping objects. The window also displays the layout state of the containers. Containers are those widgets that can store other widgets or object. Few of the examples of containers are Frames, Group Boxes, Stacked Widgets, Tab Widgets and ToolBox Widgets.

Properties Editor - Used to view and change the properties of the form and widgets. It consists of two columns, the Property column and Value column. The Property column lists property names and the Value column lists the corresponding values. To change the same property to the same value for a set of widgets, select all of them. To select a set of widgets, click one of the widgets, then Shift+Click the others one by one. When a set of widgets is selected, the properties window will show the properties that are common in all the selected widgets, and any change made to one property will be applied to the same property for all the selected widgets.

Click here to continue reading....!

tech-news