Skip to content

Instantly share code, notes, and snippets.

@psifertex
Created March 21, 2024 00:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save psifertex/b52e8c5df590f9ec271319ac2bef78ca to your computer and use it in GitHub Desktop.
Save psifertex/b52e8c5df590f9ec271319ac2bef78ca to your computer and use it in GitHub Desktop.
from PySide6.QtWidgets import QApplication, QMainWindow, QMessageBox, QPushButton
from PySide6.QtCore import Qt
import sys
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("QT Test")
button = QPushButton("Test Dialog")
button.clicked.connect(self.button_click)
self.setCentralWidget(button)
def button_click(self):
msgBox = QMessageBox(self)
msgBox.setIcon(QMessageBox.Question)
msgBox.setText("Quit?")
msgBox.setStandardButtons(QMessageBox.Save | QMessageBox.Discard | QMessageBox.Cancel)
result = msgBox.exec()
match result:
case QMessageBox.Save:
print("Save")
case QMessageBox.Discard:
print("Discard")
case QMessageBox.Cancel:
print("Cancel")
return True
app = QApplication(sys.argv)
window = MainWindow()
window.show()
app.exec()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment