Created
December 5, 2021 23:40
-
-
Save leixingyu/f0b339a3fb66c62c87b6ffadf7777df2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainWidget(QtWidgets.QMainWindow): | |
def __init__(self, parent=None): | |
self.connectSignal() | |
def connectSignal(self): | |
self.someBtn.clicked.connect(self.openCustomWidget) | |
def openCustomWidget(self): | |
# initialize with a widget and a layout | |
self.customWidget = QtWidgets.QWidget() | |
layout = QtWidgets.QHBoxLayout(self.customWidget) | |
# title | |
self.customWidget.setWindowTitle('Error Log') | |
# set window display behavior | |
self.customWidget.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint) | |
# set window icon (using a built-in icon) | |
name = "SP_MessageBoxCritical" | |
style = self.customWidget.style() | |
icon = style.standardIcon(getattr(QtWidgets.QStyle, name)) | |
self.customWidget.setWindowIcon(icon) | |
# add custom elements here | |
message = "happy new year" | |
errorLabel = QtWidgets.QLabel(messages) | |
scrollArea = QtWidgets.QScrollArea() | |
scrollArea.setWidgetResizable(True) | |
scrollArea.setWidget(errorLabel) | |
# finalize | |
layout.addWidget(scrollArea) | |
self.customWidget.show() | |
def showWindow(): | |
win = MainWidget() | |
try: | |
win.close() | |
except: | |
pass | |
win.setAttribute(QtCore.Qt.WA_DeleteOnClose) | |
win.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment