Linking a qtDesigner .ui file to python/pyqt?

前端 未结 12 1393
北海茫月
北海茫月 2020-11-28 01:33

So if I go into QtDesigner and build a UI, it\'ll be saved as a .ui file. How can I make this as a python file or use this in python?

12条回答
  •  余生分开走
    2020-11-28 02:04

    I found this article very helpful.

    http://talk.maemo.org/archive/index.php/t-43663.html

    I'll briefly describe the actions to create and change .ui file to .py file, taken from that article.

    1. Start Qt Designer from your start menu.
    2. From "New Form" window, create "Main Window"
    3. From "Display Widgets" towards the bottom of your "Widget Box Menu" on the left hand side
      add a "Label Widget". (Click Drag and Drop)
    4. Double click on the newly added Label Widget to change its name to "Hello World"
    5. at this point you can use Control + R hotkey to see how it will look.
    6. Add buttons or text or other widgets by drag and drop if you want.
    7. Now save your form.. File->Save As-> "Hello World.ui" (Control + S will also bring up
      the "Save As" option) Keep note of the directory where you saved your "Hello World" .ui
      file. (I saved mine in (C:) for convenience)

    The file is created and saved, now we will Generate the Python code from it using pyuic!

    1. From your start menu open a command window.
    2. Now "cd" into the directory where you saved your "Hello World.ui" For me i just had to "cd\" and was at my "C:>" prompt, where my "Hello World.ui" was saved to.
    3. When you get to the directory where your file is stored type the following.
    4. pyuic4 -x helloworld.ui -o helloworld.py
    5. Congratulations!! You now have a python Qt4 GUI application!!
    6. Double click your helloworld.py file to run it. ( I use pyscripter and upon double click
      it opens in pyscripter, then i "run" the file from there)

    Hope this helps someone.

提交回复
热议问题