반응형
AttributeError: 'MainDialog' object has no attribute 'setCentralWidget' 에러
import sys
from PyQt5.QtWidgets import *
from PyQt5 import uic
main_ui = uic.loadUiType('_uiFiles/main.ui')[0]
class MainWindow(QDialog, main_ui):
def __init__(self):
super().__init__()
self.setupUi(self)
if __name__ == "__main__":
app = QApplication(sys.argv)
main_dialog = MainWindow()
main_dialog.show()
app.exec_()
해결 방법
Qt Designer에서 폼을 만들 때 Main Window를 선택하고 클래스 부분에 사용하지 않았기 때문에 발생한 오류다.
QMainWindow를 import하고
from PyQt5.QtWidgets import QApplication, QMainWindow
# from PyQt5.QtWidgets import *
메인 윈도우 부분의 QDialog를 QMainWindow로 변경하면 된다.
class MainWindow(QDialog, main_ui): <-- 이 부분
def __init__(self):
super().__init__()
self.setupUi(self)
class MainWindow(QMainWindow, main_ui): <-- QMainWindow 로 변경
def __init__(self):
super().__init__()
self.setupUi(self)
참고 링크stack overflow - https://stackoverflow.com/questions/41458676/attributeerror-qdialog-object-has-no-attribute-setcentralwidget
반응형
'Programming > Python' 카테고리의 다른 글
[Python] PyQt5 특정 리스트, 딕셔너리를 리스트 뷰에 표시 (0) | 2020.01.31 |
---|---|
[Python] PyQt5 메시지 박스 / QMessageBox (0) | 2020.01.14 |
[Python] PyQt5 List View에 아이템 추가하기 (0) | 2020.01.10 |
[Python] PyQt5 새 창 만들기, 새 창 띄우기 (0) | 2020.01.09 |
[Python] .ui 파일을 파이썬에서 로드, .py로 변환 (0) | 2020.01.09 |
댓글