error_dialog.py

2021/10/06 categories:Code| tags:Code|python|

記事に戻る

# -*- coding: utf-8 -*-
from PyQt6 import QtCore, QtGui, QtWidgets

class ErrorDialog(QtWidgets.QWidget):
    def __init__(self) -> None:
        super().__init__()
        self.resize(300, 200)
        self.setWindowTitle('エラー内容')

        self.text_browser = QtWidgets.QTextBrowser()
        self.close_button = QtWidgets.QPushButton('閉じる')
        
        w0 = QtWidgets.QWidget()
        w0.setLayout( QtWidgets.QHBoxLayout() )
        w0.layout().addItem(QtWidgets.QSpacerItem(20, 20, QtWidgets.QSizePolicy.Policy.Expanding, QtWidgets.QSizePolicy.Policy.Minimum))
        w0.layout().addWidget(self.close_button)
        w0.layout().setContentsMargins(2, 2, 2, 2)

        self.setLayout(QtWidgets.QVBoxLayout())
        self.layout().addWidget(self.text_browser)
        self.layout().addWidget(w0)

        self.close_button.clicked.connect(lambda : self.close())

    def set_text(self, text):
        self.text_browser.setText(text)

if __name__ == '__main__':
    import sys
    app = QtWidgets.QApplication(sys.argv)
    window = ErrorDialog()
    window.show()
    app.exec()

Share post

Related Posts

Comments

comments powered by Disqus