PyQt Digest

Digest, not swallow. But in Python. And of course, about Qt.

The Qt Hierarchy

leave a comment »

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?

QtCore as the name goes, has core-stuff. By core I mean simple and basic functional stuff, like data structures and associated methods, that doesn’t have anything to do with Graphics or GUI directly but provide several benefits. Things in this include classes like (a few):
  • 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).
Not just these geometry stuff, but also other classes providing timer functions, file and directory I/O, buffers, threads and concurrency control, generic containers like lists, stacks and dictionaries, etc. Everything provided is also highly optimized.

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?

QtGui deals with all things graphical and the UI both. This area includes classes for handling image files, various widgets of a UI like a progress-bar, tabbed windows, MDI interfaces, and also action classes that handle all events a user may perform, like mouse clicks, close or show events. Some of the QtGui classes (again, a few):
  • QImage – Open an image and process upon it.
  • QWidget – Draw a simple plain window.
  • QListWidget – Create a simple list-box widget to hold things.
All class associated with the look-and-feel and the working-logic of the UI and other graphical components are also enclosed within this module. This includes tree-models for showing directory hierarchy directly, printer configurations, brushes and pens for drawing shapes, etc. Almost every provided feature works perfectly across all platforms.

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.

Written by Harsh

November 23, 2008 at 4:47 pm

Posted in Qt

Tagged with , , ,

So wait, what’s Qt about? – Part 1

with one comment

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. :)

Written by Harsh

May 26, 2008 at 1:28 pm

Posted in Qt

Tagged with , ,

Follow

Get every new post delivered to your Inbox.