Important: Please read the Qt Code of Conduct -

Developing Python applications in Qt Creator

  • I haven't been able to figure out how to create a Qt application in Python with it so far. Online documentation about it appears to be scarce.How do I set up such a project in Qt Creator? Ideally I'm looking for a simple "Hello World" project that I can open in Qt Creator and use that as a starting point to build something.

  • Welcome to DevNet,

    As far as my knowledge goes you can't use python with QtCreator. However, you can use other powerful IDEs like PyCharm or powerful text editors like emacs or vim. (In this example I'm using vim)

    Programming Qt4 ( or Qt5) with Python feels basically the same as if you were writing it in C++, as in you can use Qt's documentation and tutorials. The exception being the language and the way you organize your app.

    My example doesn't show much but should give you an idea. If you use linux, do install the following packages.

    sudo apt-get install python-qt4 python-qt4-dev (I use Qt4 in this out of laziness)

    The code I use

    from PyQt4 import QtGui
    import sys
    # you can also write it as 
    # from PyQt4.QtGui import QLabel
    app = QtGui.QApplication(sys.argv)
    window = QtGui.QMainWindow()
    window.setWindowTitle("Qt Rocks!")
    widget = QtGui.QWidget()
    label = QtGui.QLabel("Hello world",window)
    layout = QtGui.QVBoxLayout()

    Screenshot added

    I use vim with several plugins, my recommendation is to use PyCharm instead (mileage may vary)

    I hope this helps you, happy coding.

  • Thank You :) But what about using pycharm in Rasberry pi

  • Since we are talking about python scripts you can simply write a script that:

    • Pushes your scripts through SCP (SSH)
    • or Use Git to pull new changes

    You can just use your desktop/laptop and leave deployment/testing later on the Raspberry Pi as you don't need to write code using the device. In theory your code should run anywhere if Python and PyQt4/Qt4 supports it.

    So wrapping it up, don't use your Rasberry pi to develop, use your desktop/laptop, it should be fine.

Log in to reply