|
| 1 | +from PyQt5 import QtCore, QtGui, QtWidgets |
| 2 | + |
| 3 | +class SizeDialog(QtWidgets.QDialog): |
| 4 | + def __init__(self, width, height): |
| 5 | + super(SizeDialog, self).__init__() |
| 6 | + self.setModal(True) |
| 7 | + self.setWindowTitle("Enter new size...") |
| 8 | + self.setSizeGripEnabled(False) |
| 9 | + |
| 10 | + self.labelWidth = QtWidgets.QLabel("Width") |
| 11 | + self.labelWidth.setMinimumSize(50, 1) |
| 12 | + |
| 13 | + self.spinBoxWidth = QtWidgets.QSpinBox() |
| 14 | + self.spinBoxWidth.setMinimum(1) |
| 15 | + self.spinBoxWidth.setMaximum(9999) |
| 16 | + self.spinBoxWidth.setValue(width) |
| 17 | + |
| 18 | + self.labelHeight = QtWidgets.QLabel("Height") |
| 19 | + self.labelHeight.setMinimumSize(50, 1) |
| 20 | + |
| 21 | + self.spinBoxHeight = QtWidgets.QSpinBox() |
| 22 | + self.spinBoxHeight.setMinimum(1) |
| 23 | + self.spinBoxHeight.setMaximum(99999) |
| 24 | + self.spinBoxHeight.setValue(height) |
| 25 | + |
| 26 | + self.cancelButton = QtWidgets.QPushButton("Cancel") |
| 27 | + self.cancelButton.clicked.connect(self.reject) |
| 28 | + |
| 29 | + self.acceptButton = QtWidgets.QPushButton("Ok!") |
| 30 | + self.acceptButton.clicked.connect(self.accept) |
| 31 | + |
| 32 | + widthLayout = QtWidgets.QHBoxLayout() |
| 33 | + widthLayout.addWidget(self.labelWidth) |
| 34 | + widthLayout.addWidget(self.spinBoxWidth) |
| 35 | + |
| 36 | + heightLayout = QtWidgets.QHBoxLayout() |
| 37 | + heightLayout.addWidget(self.labelHeight) |
| 38 | + heightLayout.addWidget(self.spinBoxHeight) |
| 39 | + |
| 40 | + buttonLayout = QtWidgets.QHBoxLayout() |
| 41 | + buttonLayout.addWidget(self.cancelButton) |
| 42 | + buttonLayout.addWidget(self.acceptButton) |
| 43 | + buttonLayout.setAlignment(QtCore.Qt.AlignRight) |
| 44 | + |
| 45 | + mainLayout = QtWidgets.QVBoxLayout() |
| 46 | + mainLayout.addLayout(widthLayout) |
| 47 | + mainLayout.addLayout(heightLayout) |
| 48 | + mainLayout.addLayout(buttonLayout) |
| 49 | + |
| 50 | + self.setLayout(mainLayout) |
| 51 | + |
0 commit comments