D
D
DanielKkk2018-04-23 15:31:38
Python
DanielKkk, 2018-04-23 15:31:38

The problem with creating a dialog box, how to implement?

There was a problem creating additional windows. There are two buttons in the ChooseWindow window, depending on pressing the button, different windows open, in one file input, in the other input sizes for the image, it is necessary that when you click on the second button, an interface with input sizes is displayed.
And when you enter the size of the window minimized.
How to implement it?
Code example:

class CreatePicture(QtWidgets.QDialog):
    def __init__(self, parent=None):
        QtWidgets.QWidget.__init__(self, parent)
        self.input_width = QtWidgets.QPushButton("Width")
        self.input_height = QtWidgets.QPushButton("Height")
        self.vbox = QtWidgets.QVBoxLayout()
        self.vbox.addWidget(self.input_width)
        self.vbox.addWidget(self.input_height)
        self.setLayout(self.vbox)
        self.input_width.clicked.connect(self.on_width)
        self.input_height.clicked.connect(self.on_height)

    def on_width(self):
        width_length, ok = QInputDialog.getInt(self, 'Width of picture in px', 'Enter width')
        if ok:
            global_variables['width'] = width_length

    def on_height(self):
        height_length, ok = QInputDialog.getInt(self, 'Height of picture in px', 'Enter height')
        if ok:
            global_variables['height'] = height_length

class ChooseWindow(QtWidgets.QWidget):
    def __init__(self, parent=None):
        QtWidgets.QWidget.__init__(self, parent)
        self.choosepicture = QtWidgets.QPushButton("Выбрать фото")
        self.createproject = QtWidgets.QPushButton("Создать проект")
        self.vbox = QtWidgets.QVBoxLayout()
        self.vbox.addWidget(self.choosepicture)
        self.vbox.addWidget(self.createproject)
        self.setLayout(self.vbox)
        self.createproject.clicked.connect(self.on_create_project)
        self.choosepicture.clicked.connect(self.on_open_file)

    def on_create_project(self):
        testGui = CreatePicture()
        testGui.resize(500, 500)
        testGui.show()

    def on_open_file(self):
        workspace = QtWidgets.QFileDialog.getOpenFileUrl(parent=self, caption="Выберите файл",
                                                         directory=QtCore.QDir.currentPath(),
                                                         filter="Image Files (*.png *.jpg *.bmp ")


if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)
    dialogWindow = ChooseWindow()
    dialogWindow.setWindowTitle('Select')
    dialogWindow.resize(200, 150)
    dialogWindow.show()
    sys.exit(app.exec_())

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question