반응형

간단한 QProgressDialog 예제 입니다.



2022. 8. 14  최초작성




실행하면 두 개의 버튼이 보입니다. 

 



“QProgressDialog 보여주기”를 클릭하면 QProgressDialog를 보여줍니다.

 



“QProgressDialog 숨기기”를 클릭하면 QProgressDialog가 사라집니다.

 



전체 소스 코드입니다.

 

import sys
from PyQt5.QtWidgets import QHBoxLayout, QPushButton, QProgressDialog, QDialog, QApplication
from PyQt5.QtCore import Qt


class MainDialog(QDialog):
    def __init__(self):
        super().__init__()

        horizontal_layout = QHBoxLayout()
        self.Button1 = QPushButton('QProgressDialog 보여주기', self)
        self.Button1.clicked.connect(self.generate)
        self.Button2 = QPushButton('QProgressDialog 숨기기', self)
        self.Button2.clicked.connect(self.hide)
        horizontal_layout.addWidget(self.Button1)
        horizontal_layout.addWidget(self.Button2)
        self.setLayout(horizontal_layout)
       
        self.Button2.setEnabled(False)
       

    def generate(self):

        self.Button1.setEnabled(False)
        self.Button2.setEnabled(True)

        self.progress = QProgressDialog('잠시만 기다리세요', '', 0, 0, self)
        self.progress.setWindowTitle("진행중...")
        self.progress.setWindowFlags(Qt.Window | Qt.WindowTitleHint | Qt.CustomizeWindowHint)
        # self.progress.setWindowModality(Qt.WindowModal) # 주석을 해제하면 항상 모든 윈도우보다 상위에 존재하게 됩니다. 
        self.progress.setCancelButton(None)
        self.progress.show()

    def hide(self):

        self.Button1.setEnabled(True)
        self.Button2.setEnabled(False)

        self.progress.hide()
       
if __name__ == '__main__':

    app = QApplication(sys.argv)

    dlg = MainDialog()

    dlg.show()
    app.exec_()


반응형

문제 발생시 지나치지 마시고 댓글 남겨주시면 가능한 빨리 답장드립니다.

도움이 되셨다면 토스아이디로 후원해주세요.
https://toss.me/momo2024


제가 쓴 책도 한번 검토해보세요 ^^

+ Recent posts