The Qt Hierarchy
So to continue about Qt, lets talk about the division of the modules in it.
There are two major (not the only) modules in Qt, namely:
- QtCore, and
- QtGui
What is QtCore?
- QPoint – Define and move co-ordinates (x,y)
- QLine – Define a line of two points (x1, y1) and (x2, y2)
- QRect – Define a rectangle starting at (x,y) and of certain (width by height).
Code to include all from this module:
from PyQt4.QtCore import *
Reference on entire QtCore | The QRect class documentation example
An example deserves a post of its own, which will come soon.
What is QtGui?
- QImage – Open an image and process upon it.
- QWidget – Draw a simple plain window.
- QListWidget – Create a simple list-box widget to hold things.
Code to include all from this module:
from PyQt4.QtGui import *
Reference on entire QtGui | The QImage class documentation example
A basic example would be the Hello World! post, but an advanced one will soon be available.
Footnotes:
The best way to learn and use Qt is to follow the Qt Documentation (The Qt Assistant comes along with the installation). Though it is C++ centric, its not much different when you use it in Python. Qt is Qt everywhere, across platforms and across languages too.
So wait, what’s Qt about? – Part 1
The first GUI toolkit on Python I tried was PyGTK. I used the available free manual and it started very smooth, with the author explaining every part of GTK and not jumping into actual usage of Python for GTK right away. What I wish to convey here is that the manuals assumed you do not know what GTK is and thus make it easier for the total newcomers.
Sadly, so far at least, this has not been the case with PyQt. The two major books I was suggested over various channels of Freenode IRC were Mark Summerfield’s Rapid GUI and Boudewijn Rempt’s GUI Programming.
The first book covers Python and then covers QT programming from the Python perspective. This means it assumes you know much about Qt’s classes already and its just gonna help you do it all the Python way instead of C++.
The second book relaxes moderately on the Python perspective but after the first 2-3 example application it tutors you through, it dives in too deep for beginner comfort. Not to mention it is also surrounded by the use of a commercial (paid) IDE called BlackAdder. This makes the learning more difficult, or perhaps more expensive if approached linearly.
Both these books however fail to mention any introduction part to the Qt class hierarchy.
For C++, on the other hand, Mark and Jasmine’s book C++ GUI Programming with Qt takes off really well with enough details about QObject, QWidget hierarchies popping in once a while.
I struggled real hard for around 2 days just to write a simple calculator application from scratch in Python due to these lack of proper documentations/manuals. I wish this does not happen to you and so I shall write things that are essentially Qt and not language-dependent in posts titled this. I do not know how many parts it will go on to but its essential and very much needed.
I shall also try to address the issues with choosing the proper IDE for PyQt development as I write up these explanatory posts. Please bear with me.
