Skip to content

Instantly share code, notes, and snippets.

@simonreeves
Last active November 5, 2020 12:32
Show Gist options
  • Save simonreeves/3f1abfc5da1e570851f27faf07b6821e to your computer and use it in GitHub Desktop.
Save simonreeves/3f1abfc5da1e570851f27faf07b6821e to your computer and use it in GitHub Desktop.
pyside2 dialog - uses https://github.com/mottosso/Qt.py
import sys
from Qt import QtCore
from Qt import QtGui
from Qt import QtCompat
from Qt import QtWidgets
class my_dialog(QtWidgets.QDialog):
def __init__(self):
QtWidgets.QDialog.__init__(self, None, QtCore.Qt.WindowStaysOnTopHint)
self.setWindowTitle('Append comment to export')
# self.setWindowIcon()
self.setSizeGripEnabled(True)
self.setFixedWidth(500)
# Works, should always stays on top now
self.setModal(True)
# Create widgets
self.CommentInput = QtWidgets.QTextEdit()
self.SaveButton = QtWidgets.QPushButton('Save')
# Create layouts and add widgets
# Make a group
Group1 = QtWidgets.QGroupBox('Please record what changes have happened in this version')
# make a layout for the group
Group1Layout = QtWidgets.QGridLayout()
# add widgets to the groups layout
Group1Layout.addWidget(self.CommentInput)
Group1Layout.addWidget(self.SaveButton)
# assign the layout to the group
Group1.setLayout(Group1Layout)
# Create top layout
Layout = QtWidgets.QVBoxLayout()
# Assign widgets to the top layout
Layout.addWidget(Group1)
# Set dialog layout
self.setLayout(Layout)
# Add button signal to greetings slot
self.SaveButton.clicked.connect(self.Save)
def Save(self):
"""
called by the button
"""
self.accept()
def GetValues(self):
"""
Return Value method
"""
return self.CommentInput.toPlainText()
def main():
# Grab an instance already open (if already in an application)
app = QtWidgets.QApplication.instance()
# Create the Qt Application
if app is None:
app = QtWidgets.QApplication(sys.argv)
# Create the dialog in memory (an instance of the class)
my_dialog_instance = my_dialog()
print('my_dialog_instance: {}'.format(my_dialog_instance))
# if checks if it returns 1 or 0 and if so to cancel or accept the dialogs return
if my_dialog_instance.exec_():
# If the dialog was accepted, the object still persists and we can retrieve data from it
print('my_dialog_instance.GetValues(): {}'.format(my_dialog_instance.GetValues()))
else:
print('dialog cancelled')
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment