1. 분석할 소스코드 확인하기

2. Qt 예제 소스코드

더보기

2.1. 기본 소스코드

아래는 Qt에서 Pyside6 템플릿을 실행하면 최초 구현되어 있는 소스코드입니다.

# This Python file uses the following encoding: utf-8
import sys

from PySide6.QtWidgets import QApplication, QWidget

# Important:
# You need to run the following command to generate the ui_form.py file
#     pyside6-uic form.ui -o ui_form.py, or
#     pyside2-uic form.ui -o ui_form.py
from ui_form import Ui_Widget

class Widget(QWidget):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.ui = Ui_Widget()
        self.ui.setupUi(self)


if __name__ == "__main__":
    app = QApplication(sys.argv)
    widget = Widget()
    widget.show()
    sys.exit(app.exec())

 

 

2.2. main 분리 후 소스코드

# widget.py

from PySide6.QtWidgets import QWidget
from ui_form import Ui_Widget

class Widget(QWidget):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.ui = Ui_Widget()
        self.ui.setupUi(self)
# main.py

import sys
from PySide6.QtWidgets import QApplication

from widget import Widget

if __name__ == "__main__":
    app = QApplication(sys.argv)
    widget = Widget()
    widget.show()
    sys.exit(app.exec())

 

3. PyCharm & Qt 개발 환경 비교