Developing Cross Platform Application using Qt, PyQt and PySide : Introduction - Part 1 of 5

The blend of Qt in Python

The blend of Qt in Python
(Image taken from PyQT Wikipedia article)

Before we even begin this new article series, I would like to emphasize one thing : I would love to make this blog as a great starting point for you to learn many tidbits in Python software development. For example, even though what we learn is somewhat an advance topic in Python application development, I will always start with the basic. This eventually create a vast array of article series : Flask, Django, ProgrammedMe, Kivy, etc. The reason is quite simple : if you are new to a Python topic, you can always refer to the first article in a series to be able to follow the rest of the articles. 

In this new article series, the target that I want to accomplished is to introduce you to the Python Android application development using either PySide or PyQt. Yes, previously you have been introduced to Kivy to develop Python application in Android. But, before going even further in Kivy, lets have a comparative experience on Python application development using another libray : PySide/PyQt. This come with a requirement : you must be introduced to and able to develop a PySide/PyQt application in its Desktop environment. Then, we move to its Android development.This is necessary, as differ with Kivy that directly support mobile application development in its first inception, Qt support in mobile development was gradually introduced.

Great. What are you waiting for? Lets go!

A Gentle Introduction to Qt, PyQt and PySide

Although in this blog I haven't officially talked about cross platform GUI toolkit for Python, the truth is, I have already show you how use TkInter (which is one in many libraries in doing cross platform GUI application using Python) in this article. Needless to say, trying to elaborately explained all of the existing GUI toolkit libraries and then choosing one of them as the center of discussion/talk/tutorial, may start a discussion that lead to a flame war : all GUI toolkits have their own loyal fans. For example, as I am going to focus my discussion on Qt, Linux users may aware of its legendary rival : GTK+. Now, for those who would like to know its head to head comparison, you may headed to this WikiVs article. There you go. I just cleaned my hand.. Laughing

Qt is a C++ application framework brand and product that have its trademark being transferred from Trolltech (its original founder), to Nokia (greatly define path for Qt in mobile application development) and finally to Digia (continuing development lead, support and maintaining commercial license for Qt). Interesting thing about Qt is, even though it started as a proprietary product by Trolltech, throughout its epic development history, finally it became an Open Source LGPL product. The development of Qt is not in a closed manner inside Digia lab, but in an open governance mechanism coordinated by Qt Project. Everyone is invited to join in the Qt development!

You may wonder, "What do Python got to do with a C++ application framework?" To make the answer short : this is largely because PyQt, which is the work of of Phil Thompson starting in the late '90s, that open the door for Python developers to use Qt in their application development. It create an enormous possibility for Python developer to use Qt in much more pythonic way. Using Phil Thompson own words in foreword of the book Rapid GUI Programming with Python and Qt : "My primary goal has always been to allow Python and Qt to work together in a way that feels natural to Python programmers, while allowing them to do anything they want in Python that can be done in C++. The key to achieving this was the development of SIP". Eventually PyQt become the major product of Phil Thompson founded software consultation firm, Riverbankcomputing.

Until mid 2009, PyQt was the sole product for Python binding for Qt. This sole domination was somewhat challenged by Nokia (at that time was still owned Qt trademark) when it released PySide, which is also a Python binding for Qt. "Two product with exactly the same purpose? Why?", you may wonder. It's true. The reason is, because Nokia and the developer at Riverbankcomputing failed to reach an agreement to include LGPL in PyQt license. This means, without commercial PyQt license, you'll have to make your application that use PyQt to be also GPLed (in simple term, you must make your application source code available to the rest of the world). Up until now, Python developer who tried to use Qt in their application will be faced with two options : PyQt or PySide? The good news is, both were having (almost) the same level of compatibility in its Python level, which means Python developer can switch to use either PyQt or PySide in their application development, with little or no modifications.

The Edge of Changes 

For those who would love to develop Python application that leverage Qt, will realize that we are somewhat standing in the bleeding edge of three changes :

  1. Python itself was undergo changes from Python 2 to Python 3. Throughout its development history, Python 3 is the only release that is not backward compatible. This means application that developed using Python 2.x is not guaranteed to work in Python 3. With a large base of applications, frameworks, libraries and utilities still being developed using Python 2.x, this will somewhat make Python community hesitate to move forward to Python 3.x. You will find a lot of popular libraries simply said that it currently didn't support Python 3.
  2. Starting from Qt 4.7, Qt Quick were introduced as a new framework leveraging Javascript for constructing application and its GUI. This is a competing API with the traditional (or shall I say legacy?) Qt C++ UI framework. Qt Quick leverage QML which is a descriptive language to define your application UI. QML were much like Kv language in Kivy framework. Although Qt Quick initially targeted toward mobile development, chances are it won't take long before it moves to the desktop environment. For the moment, you really have to choose one between two options in developing GUI application using Qt : Javascript QML or C++ Qt UI ?
  3. Although PyQt already support Qt 5 (many thanks for this!), it dropped support for Python 2.7. Phil would like us to move forward to Python 3. What about PySide? Frankly, the current release of PySide not yet supporting Qt 5. According to PySide roadmap, "Further down the road (but not that far) is improving things at the C++ level and working on supporting qt5". Well, I believe we haven't got that support established then!

So, what's the best decision for the current state of changes in Python, Qt and PyQt/PySide? I will give a standard (and safe) answer, "It greatly depends on your application requirement or needs", or even on your boss! If however we are in the state of exploring things (like me in this blog), well, let just explore all of them and see whether interoperability, compatibility or even porting tools exists for either choices. 

To make things even better, we are not restricting our exploration in Python only. We will also have a look on how it's done in its C++ counterpart. Using my personal opinion, I really love to have a holistic view for all ways, before choosing one way that will fit to the current application requirement.This will make my understanding better and thorough.

Installing Qt, PyQt and PySide

At the moment, I love working on Windows, with several occasion revert to Linux / Mac OS X when necessary. Therefore, for installation of this technologies, I am going to use its official download page (not using either apt, yum, brew, MacPorts, etc), listed below:

  1. Download Qt 4 or Qt 5 from this download page. This is required if you like to develop Qt using C++ language. If not, you can simply skip this download. Choose the one that match your operating system.
  2. Download PyQt 4 or/and PyQt 5. Downloading one of this PyQt version will include free Qt binaries (and its tools) in the appropriate version that required to run your PyQt application, which is why you don't need to download Qt separately.
  3. If you want to use a great IDE for Python development in Windows, you can try to use Python Tools for Visual Studio. This is what I enjoyed to use in my current Python application development. Another solution exist of course, such as PyCharm. However, if you are about to develop Qt using C++, the Qt distribution already include QtCreator : a cross platform C++ IDE specifically designed to develop C++ Qt or Qt Quick application. With special simple configuration, it can also be use to develop non-Qt C++ application.

Downloading the above prerequisites will somewhat take a helluva time. So, grab a coffee..Or beer. I never tried beer though.. Laughing

What's Next?

This article should be regarded as a general introduction to Qt, PyQt and PySide. Moreover, I also laid out the current situation and condition of doing Qt development in Python using either PyQt or PySide. We will gradually increased our exploration in the next few articles starting from the development of a useful Desktop application (I am thinking of an application that fall in the category of productivity application) until the development of a Qt/PyQt/PySide mobile application (I am thinking of developing an alphabet match maker game for my kids).

By completing this article and installing the required tools, I assume that you have the interest and curiosity to develop Qt/PyQt/PySide desktop or mobile application. In that case, stay tuned for my next articles regarding this topic!

But my subsequent article will continue with the exploration of an education Kivy application though. Sorry.. Tongue out




Leave comments

authimage
  • Hi Bill,

    I always thought that Python user experience in desktop environment should be improved more. Even in its Windows distribution, I am not that satisfy with how Python and its packages (including PyQt/PySide) was installed in windows machine.

    Your comment is synced with my current thinking: we ought to have a better/standard/accepted way of installing binaries for the sake of our users. DotNet is very good in this manner. Java is good enough. Python? Seriously, we got to do something about it...

    Thanks,
    Eko

    • eko
  • PyQt vs PySide:
    I have finally decided to use PySide simply because PyQt is only available as Windows binaries for Python versions 2.7 and 3.3.
    I can't expect the potential users of the tool that I'm developing to migrate to a new version of Python just to use the tool.

    • Bill Hayes
  • @Daverz Great!
    Will gladly follow your tracking result on this matter :)

    • eko
  • @Daverz no, we don't have too much time on our hands. There is just one member who is a bit OCD - speaking for him ;-)

    • Carl Trachte
  • Thanks for your feedback. I'll try to track down the original owner of the logo.

    • Carl Trachte
  • @Darez Well, I guess that's what their role in our Python world! ;)

    • eko
  • @David Boddie Great! :)

    Qt really intrigued me. As its history of development was rather.. epic in my opinion. It really express (and drove) the changes in our software development paradigm.

    Really passionate with it.
    Thanks, I'll do my best in bringing this series into a wonderful learning experiences in cross platform development using Qt

    • eko
  • The PSF Trademarks Committee obviously has too much time on their hands.

    • Daverz
  • Actually, what you wrote is fine. I was simply reacting to the way you wrote that, "finally it became an Open Source LGPL product." This could imply to some people that, before it was licensed under the LGPL, it was not open source, which would not be correct.

    Good luck with your series.

    • David Boddie
  • @Carl Trachte
    Thanks for your concern on this matter. I would love to modify the logo based on your input, but I took this logo from PyQt article (now I added its link in the article). And to better clear this situation, could it be that the logo from its wikipedia article be corrected first?

    Thanks!

    PS : I just added my contact info in this blog

    Ref : http://en.wikipedia.org/wiki/PyQt

    • eko
  • @david boddie : Thanks for your sincere comment!
    Hm, I have an understanding that at it initial inception, it was a proprietary product : even in its Qt/X11 for Unix. Or, is it at the first time of it arrival, it already possessed with GPL license? That's why I only state its initial license as proprietary and its final license to be in LGPL license, complete with its Wikipedia article, so reader can read it fully there

    • eko
  • I couldn't find your contact information on the page so I am commenting.

    The PSF Trademarks Committee noticed that the QT part of your logo is either touching or almost touching the two snakes logo. Could you put an easily visible few pixels of space between the QT part of the logo and the Python 2 snakes?

    Thank you for your attention to this.

    Carl Trachte
    PSF Trademarks Committee Member

    • Carl Trachte
  • Just to correct a misunderstanding about the Qt license: it was GPL before the LGPL license was added as an option. Before it was licensed under the GPL, it was licensed under the QPL which is an open source license. The Wikipedia article you linked to covers this in more detail.

    • David Boddie

Copyright(c) 2014 - PythonBlogs.com
By using this website, you signify your acceptance of Terms and Conditions and Privacy Policy
All rights reserved