Qt 2.x and Python 1.6 bind together well

By Boudewijn Rempt, Unix Insider |  Development Add a new comment

In principle, the X Window system provides a programming interface for all Unix and many other operating systems. However, X Window is too low level to be practical for most projects, which is why dozens of higher-level abstractions have been defined to simplify GUI construction.


Most GUI toolkits for Unix are presented through their C programming interfaces or, occasionally, with Java. But the number of toolkits available to Python programmers is remarkable, which is one of the reasons we believe Python is a far better vehicle for exposition and most development. One of the most interesting of these toolkits, PyQt, has just become even more interesting.

What Qt 2.x gives

Version 0.12 of PyQt supports Qt 2.x. Qt is the full-featured, Unicode-aware, cross-platform, theme-configurable toolkit from Troll Tech that's the basis for the upcoming KDE2 desktop for Unix. Qt provides an abundance of widgets, customizable features, high-quality documentation, and extensibility. We detail its capabilities below.


Conventional programs operate best with the Roman alphabet and the English language. Unicode, however, is a relatively new encoding standard that makes it practical for programmers to manage almost any human language. Qt supports Unicode on all platforms.


While much of Qt's early buzz came from Linux practitioners, the toolkit is equally at home with any Unix or Windows OS. Variations are also available for QNX and a few other specialized OSs.


You can customize Qt with colors and fonts, and you can customize the shape of each widget. Your application can, at the runtime request of the user, look like a Windows application, a Motif, or a CDE, and if you want to imitate NextStep, Mac OS, or Swing, it's straightforward to create code that does just that.

Figure 1. Qt offers a wide array of typefaces and fonts


Several important products already rely on Qt, including the KDE and KDE2 desktops, Kylix, YAST 2, QCad, and the Opera browser.


On a technical level Qt is a C++ library with support for interesting features including signals and slots. Slots, which can be thought of as a kind of weak reference, do the work in Qt that callbacks accomplish for other GUI toolkits. Slots promote better type safety than do callbacks, and they are especially handy for model-view-controller (MVC) designs. MVC is widely recognized as a clean, rational, object model that naturally expresses sound GUI design.

Qt for Python

C++ programmers aren't the only ones enjoying Qt's benefits. Thanks to the work of independent consultant Phil Thompson, all of its power is now available for Python developers too, including signals and slots, Unicode strings, themes, C++ class variables, and operator overloading.


The documentation available from Troll Tech for Qt is of equal benefit to Python developers. PyQt binds Qt to Python in such a natural way that PyQt programmers read the C++ documentation with little more than a mental regular expression for translation. The PyQt distribution also includes many example programs, PyQt's mailing list is helpful, and its tutorial has a record of success.


PyQt is free for Windows and Unix, while Qt itself is free for Unix. The Qt libraries for Windows are available only under a commercial license from Troll Tech.


Qt2 is richer than most alternative GUI toolkits, and the PyQt binding is correspondingly weighty, at about 5 megabytes for common platforms. However, it is a shared library, so running two PyQt applications generally fills up little more than 5 megabytes instead of 10.


Because KDE2 isn't even in alpha (as of mid-May 2000), no bindings are available for it. Your current choice is between either Qt 1.x with KDE 1.1.2 desktop support, or Qt 2.x support without KDE. KDE desktop integration offers common resources like icons, toolbar images, session management, and desktop-wide look-and-feel customization. KDE2 will also offer component embedding (KParts) and a distribution object model (DCOP). Work has already started on preliminary KDE2 bindings.

A quick tutorial

To deepen your understanding of PyQt's key concepts, you'll want to work through a small PyQt demonstration. For this purpose, one of us (Rempt) has selected a useful little project: a character selection window with Unicode support. You can download its source at: http://www.valdyas.org/python/qchm.tgz.

    Add a comment

    Post a comment using one of these accounts
    Or join now
    At least 6 characters

    Note: Comment will appear soon after you have activated your account.
    Obscene/spam comments will be removed and accounts suspended.
    The information you submit is subject to our Privacy Policy and Terms of Service.

    ITworld LIVE

    DevelopmentWhite Papers & Webcasts

    White Paper

    HP NonStop SQL Fundamentals whitepaper

    This whitepaper offers a detailed look into the fundamentals of HP NonStop SQL solutions. See how this system delivers unprecedented levels of application availability with fail-safe data integrity and meets the needs of enterprises with large-scale business critical applications.

    White Paper

    Nebraska Medical Center case study

    See how the Nebraska Medical Center implemented a SQL solution to make information more readily available to streamline operations, improve patient care and facilitate medical research with an enterprise solution running on HP NonStop servers.

    White Paper

    Concepts of NonStop SQL/MX

    For DBAs and developers who are familiar with Oracle solutions and want to learn about NonStop SQL/MX, this whitepaper provides an overview of the similarities and differences between the two products-with a specific focus on implementation.

    White Paper

    6 Things Your CIO Needs to Know About Requirements

    If your organization is not predictably successful on technology projects, there is likely an issue in requirements. CIOs must take action and own requirements maturity improvement. There are 6 main things a CIO must know about requirements.

    Webcast On Demand

    User Experience Monitoring

    In this webinar, you will learn hints & tips for improving end-user response times from Forrester Research analyst, Jean-Pierre Garbani.

    Sponsor: Nimsoft

    See more White Papers | Webcasts

    Ask a question

    Ask a Question