qcha
qcha

Reputation: 583

How to use Qt designer with a preexisting Python code?

I am currently trying to make GUI in python. For this, the way I found is to use Qt Designer to generate a graphical interface .ui, and to convert it in .py with PyQt4, to edit functions in python.

The question I have is then how to modify the graphical interface without having to set up again the whole python code ?

Indeed, if I want for instance to add a button in the interface, with a particular function, I would simply like to add this function in the .py, without doing again the whole .py

To sum up, I would like to be able to update in the future my interface easily.

Do you have any idea ?

Thank you in advance ! :)

Upvotes: 1

Views: 4455

Answers (1)

jonspaceharper
jonspaceharper

Reputation: 4367

Answer. If you're going to modify code from Qt Designer (via pyuic), understand that the process is one way:

.ui file -> pyuic -> .py

pyuic (and uic, the Qt/C++ equivalent) are one way code generators. You can't take existing Python code and make a .ui file for Qt Designer.

Addendum
That said, you have three choices:

  • Stick with .ui files. Make your changes in Qt Designer and have pyuic convert it.
  • Create the initial .ui file to look the way you want, convert to Python, and hand-code from there on. I occasionally do this, but will keep the .ui file around so I know what things should look like.
  • Write it all by hand. In my experience, with time and practice, coders find this comes more naturally and rely on Qt Designer less and less.

Personally, I will create a mockup of complex forms or dialogs in Qt Designer for visual reference, but do all of the coding myself.

Upvotes: 2

Related Questions