Skip to content

Instantly share code, notes, and snippets.

@leixingyu
Created December 5, 2021 23:40
Show Gist options
  • Save leixingyu/f0b339a3fb66c62c87b6ffadf7777df2 to your computer and use it in GitHub Desktop.
Save leixingyu/f0b339a3fb66c62c87b6ffadf7777df2 to your computer and use it in GitHub Desktop.
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