Make PyQt syntax highlighting work when loading from .ui file

Question:

If elements of a PyQt/PySide GUI are defined programmatically, then any IDE can easily understand what they are, do syntax highlighting, show suggested methods etc. For instance, it may look like this in VS Code:

enter image description here

However, if the GUI is not defined programmatically, but loaded from an *.ui file, the IDE has no clue about what element is what:

enter image description here

This makes the development a bit more time consuming (need to check available methods somewhere else + troubleshooting errors takes longer). Neither is it possible to use linters in this case.

Is there any way to let the IDE know what object in the *.ui file belongs to what class?

Asked By: aadiyatul

||

Answers:

It is because there is no file that the IDE can parse. Because the UI is created from the ui file at runtime. In my projects I used pyuic to create the moc python file from the ui file and imported it. After each change of the ui file the moc must be created again. I do this with a bash script.

pyuic input.ui -o output.py

Answered By: Marco F.