Introduction to PyQt: light-weight cross-platform Solution for Qt

While i was getting handy with Qt, came the problem of porting the application to the other platforms. For me, the main aim while jumping in Qt application development is to make the application run on embedded boards like mini2440, Raspi etc. and this time the board was Raspberry Pi.
There was some UI based project to be ported to Raspi, which required the cross-compiling of whole QT IDE for the Raspi, and i got something called qtonpi. Which, i felt, would require some tedious long hours, which i didn’t have.
Probably you will get this in my next blog on Qt.
But for now, there was another option called (drums beat…) PyQt. 😛

PyQt

Easy and light weight PyQt. it worked as magic. Almost every linux distribution has python installed and all you need is a PyQt dev-kit, which basically binds the Qt APIs to the python. It is really a light-weight package which can be easily installed in almost all linux-distros in all architectures.
Lets get started:

Setting the work environment and installations:

The dev-kit can be found in synaptic manager or at terminal by typing:-

$sudo apt-get install pyqt4-dev-tools

thats all 😛

Working with python scripts:
1. Create a script file with .py extension
2. There are two options:
a. Either add #!/usr/bin/python to the first line of the file
Reason: originally, unix did not know any field by its extension, so we have the put this c-bank inside the file to let it know which script it is.

b. Or simply write python before the file name like $python abc.pyWorking with pyqt4:
a.Design your GUI form in QtCreator to save time and use pyuic4 to compile the .ui file to .py file
(basically python-ui-compiler generate the corresponding code for python from .ui file)

$pyuic4 -x abc.ui -o abc.py

$python abc.py

b.Simply start writing your python script from scratch.

Since Qt contains a lot of classes, These classes have been categorized in several modules to ease their access: