Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Developing Python applications in Qt Creator

Tags:

python

qt

I've developed a few Qt projects in C++ using Qt Creator in the past, but now I want to experiment with the Python implementation of Qt. I discovered that Qt Creator 2.8 and higher support Python, but 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.

like image 787
Pieter Avatar asked Jun 07 '14 19:06

Pieter


People also ask

Can I use Qt Creator for Python?

Yes, Qt-Creator is a C++ IDE, with little support for other languages but since version 2.8. 0 a quite basic python support has been added. That said you can use Qt-Designer (the form building tool), Qt-Translator (the translate tool), etc... easily with python.

Does Qt design studio support Python?

Getting Started with Pretty much everything you can do with Qt, you can now do in Python! Check out our how-to guides, tutorials, and examples to get you on the right track from day one.

Is Qt Python good?

Python and Qt are great for writing desktop apps: Qt gives you speed, cross-platform support and stylability while Python makes you more productive.

How do I run a Python script in Qt?

Currently, Qt Creator allows you to create Python files (not projects) and run them. It also has syntax highlighting, but it lacks more complex features such as autocomplete. Now, go to File->New File or Project->Python and select Python source file. To run the created script: Tools->External->Python->RunPy.


1 Answers

Currently, Qt Creator allows you to create Python files (not projects) and run them. It also has syntax highlighting, but it lacks more complex features such as autocomplete.

Running scripts requires some configuration (I used this tutorial). Open Qt Creator and go to Tools->Options->Environment->External Tools. Click Add->Add category and create a new category (for example, Python). Then, select the created category and click Add->Add Tool to create a new tool - RunPy for example. Select the created tool and fill the fields on the right:

  1. Description - any value
  2. Executable - path to python.exe
  3. Arguments - %{CurrentDocument:FilePath}
  4. Working directory - %{CurrentDocument:Path}
  5. Environment - QT_LOGGING_TO_CONSOLE=1

You get something like this:

enter image description here

Now, go to File->New File or Project->Python and select Python source file. To run the created script: Tools->External->Python->RunPy.

You can also add pyuic to it the same way: Click again on the Add->Add Tool button to create a new tool - PyUic now. Select it again and fill the fields on the right:

  1. Description - any value
  2. Executable - path to pyuic5
  3. Arguments - -o UI%{CurrentDocument:FileBaseName}.py -x %{CurrentDocument:FilePath}
  4. Working directory - %{CurrentDocument:Path}
  5. Environment - QT_LOGGING_TO_CONSOLE=1

Then you should have PyUic connected as well.

like image 198
NorthCat Avatar answered Oct 05 '22 22:10

NorthCat