How do you load .ui files onto python classes with PySide?

前端 未结 1 1333
攒了一身酷
攒了一身酷 2020-12-13 11:23

I\'ve used PyQt for quite a while, and the entire time I\'ve used it, there has been a pretty consistent programming pattern.

  1. Use Qt Designer to create a .ui f
相关标签:
1条回答
  • 2020-12-13 11:35

    I'm doing exactly that with PySide. :)

    You use this https://gist.github.com/cpbotha/1b42a20c8f3eb9bb7cb8 (original by Sebastian Wiesner was at https://github.com/lunaryorn/snippets/blob/master/qt4/designer/pyside_dynamic.py but has disappeared) - which overrides PySide.QtUiTools.QUiLoader and supplies a new loadUi() method so that you can do this:

    class MyMainWindow(QMainWindow):
        def __init__(self, parent=None):
            QMainWindow.__init__(self, parent)
            loadUi('mainwindow.ui', self)
    

    When you instantiate MyMainWindow, it will have the UI that you designed with the Qt Designer.

    If you also need to use custom widgets ("Promote To" in Qt Designer), see this answer: https://stackoverflow.com/a/14877624/532513

    0 讨论(0)
提交回复
热议问题