PyQt4: Displaying Windows

While coding in PyQt, one should be little familiar with both the python language and Qt Gui programming.

How to write a minimal skeleton code:
First we have to add the following line to the script to avoid writing python for executing each script 😛
#!/usr/bin/python

Thereafter all the necessary modules will have to be imported. sys is needed to initialise the QApplication. QApplication is a kind of parent application in which all the GUI components work. According to Qt documentation-

“The QApplication class manages the GUI application’s control flow and main settings. It contains the main event loop, where all events from the window system and other sources are processed and dispatched. It also handles the application’s initialization and finalization, and provides session management. It also handles most system-wide and application-wide settings. For any GUI application that uses Qt, there is precisely one QApplication object, no matter whether the application has 0, 1, 2 or more windows at any time.”

QtGui is needed here if we want to display widget. If no widget is to be displayed then this line can be dropped.

import sys
from PyQt4 import QtGui

The main() function in C is analogous to the following line in python:

if __name__==’__main__’:
a=QtGui.QApplication(sys.argv)
# this will create an application named ‘a’initialised with a command-line parameter.

sys.exit(a.exec_())
#application is executed.

Now if we want to display any widget or window, we have to write it between the above two lines.

widget=QtGui.QWidget()
widget.setWindowTitle(‘simple’)
widget.show()

Running the final code will display a Widget.

#!/usr/bin/python

import sys
from PyQt4 import QtGui

if __name__==’__main__’:
a=QtGui.QApplication(sys.argv)

widget=QtGui.QWidget()
widget.setWindowTitle(‘simple’)
widget.show()
sys.exit(a.exec_())

helloworld

Advertisements

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
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 Read the rest of this entry

Serial Port Interfacing In Qt

Well, for an embedded system guy, serial port is one of the most popular way to make your PC communicate with a target board, be it SBC or some serial based automation sort of work. Now, challenge is to use your own serial terminal software 😛 Well that’s the least what can be expected from a Qt Application developer.

Gui for the application

So this post is all about building an application which opens a serial port, and communicate with it.  Read the rest of this entry

h@ck your Xbox Controller

All the blog data for some of the posts have been moved to my other site.  Will continue here after their backup 🙂

http://www.embedded4fun.com/hck-your-xbox-controller/

Plug n Play Duino : A New Approach

All the blog data for some of the posts have been moved to my other site.  Will continue here after their backup 🙂

http://www.embedded4fun.com/plug-n-play-duino-a-new-approach/

Robotic Palm! this way !!

All the blog data for some of the posts have been moved to my other site.  Will continue here after their backup 🙂

 

http://www.embedded4fun.com/robotic-palm-this-way/

RFID based attandance & dynamic Modification of entries

All the blog data for some of the posts have been moved to my other site.  Will continue here after their backup 🙂

http://www.embedded4fun.com/rfid-based-attandance-dynamic-modification-entries/

Kinect Based Home Automation!

All the blog data for some of the posts have been moved to my other site.  Will continue here after their backup 🙂

http://www.embedded4fun.com/kinect-basics-with-robotics/

 

Compile your first kernel!!

All the blog data for some of the posts have been moved to my other site.  Will continue here after their backup 🙂

http://www.embedded4fun.com/kinect-basics-with-robotics/

Kinect basics with Robotics!

All the blog data for some of the posts have been moved to my other site.  Will continue here after their backup 🙂

http://www.embedded4fun.com/kinect-basics-with-robotics/