Jeśli jesteś właścicielem tej strony, możesz wyłączyć reklamę poniżej zmieniając pakiet na PRO lub VIP w panelu naszego hostingu już od 4zł!

Learning Python Qt Programming with PyQt & PySide

Learning Python Qt Programming with PyQt & PySide


Qt is a cross platform application framework that is made up of not only a GUI widget toolkit, but also classes for working with OpenGL, SQL databases, threading, network protocols (HTTP, FTP, UDP, TCP) and much more. Currently Python has two separate bindings for the Qt framework: Pyside and PyQt. In this post we look at Pyside and PyQt and the resources that exist for learning them.

Pyside or PyQt?

Both Pyside and PyQt have full Python bindings for Qt 4.7 and are available for Mac, Windows and Linux. The main difference between the two is how they are licensed. PyQt is developed by River Bank Computing and is available under the GPL or a commercial license. This means that if your application is open source you can use the free GPL version, but if your application is closed source you need to buy the commercial license (350 GBP). Pyside is licensed under the LGPL so it can be used in both open and closed source applications with no cost. In addition to the standard Desktop bindings, Pyside is also available for the Maemo and MeeGo mobile platforms.

Because Pyside is a relatively young project the majority of articles and tutorials on the web are titled with PyQt. Don’t let this put you off if you intend only to use Pyside. For the most part PyQt and Pyside are API compatible and all differences between the two projects are listed on the official wiki.

Qt Designer

Qt Designer is a layout and forms GUI builder. Developers can drag and drop Qt widgets (buttons, lists, tables, menus, inputs etc.) onto a window and then resize and position them how they want their application to look. Once the GUI is designed it can then be exported to an XML dialect and loaded into PyQt or Pyside. The following tutorials are for getting started and using Qt Designer:

Learning Python Qt

An Introduction to PyQt by Mark Mruss of LearningPython is an excellent beginners introduction to PyQt. It assumes no prior knowledge of PyQt or GUI programming and walks you through creating a basic hello world window.

Jan Bodnar of Zetcode has written a great series of tutorials introducing PyQt 4. They cover menus, signals, layouts, basic widgets and concludes by writing a tetris game. Zetcode is probably the best single resource for learning PyQt as it covers much of the API. All of the tutorials are well written and have clear code snippets and screenshots to accompany each example.

PyQt By Example, by Roberto Alsina, is a five part tutorial that walks you through creating a to-do list application. It is extremely detailed and covers things like database interaction using Elixer/SQLAlchemy and designing the UI in Qt Designer. This tutorial shows you how to build a full featured GUI application using PyQt and is perfect for those who are new to Qt and have done little to no GUI programming before.


There are currently two books that cover Python Qt4.X and one book that covers Python Qt2.X. GUI Programming with Python: QT by Boudewijn Rempt was written in 2001 and covers the PyQt 2.X and some 3.X bindings. Although this is outdated and not available for print anymore, it is free to read online so you may pick up some tips or tricks. Rapid GUI Programming with Python and Qt: The Definitive Guide to PyQt Programming by Mark Summerfield was written in October 2007 and covers PyQt 4.2 and 4.3. This is probably the single most useful resource as it covers the majority of the PyQt API as well as GUI programming design patterns. Summerfield has provided updated code examples from the book that are compatible with PyQt 4.7 and Pyside, they are available on the book’s website. Advanced PyQt4, by Jan Bodnar (writer of Zetcode), is a 248 page ebook that focuses on some of the lesser documented and advanced parts of PyQt. This includes graphics, layout management and model/view widgets such as QTableView, QListView and QTreeView. Although I have not read it, the summary, authors reputation and price ($23) suggests this would be a very good book to buy.


var d = new Date();
r = escape(d.getTime()*Math.random());

Posted Kwiecień 29th, 2011 in WEB and PHP Development.

Leave a response: