Everything that I found on the Internet and tried it commented out. None of these options helped me. Tell me what am I doing wrong? Here is a piece of code:
import sys from PyQt5 import QtCore, QtGui, QtWidgets from PyQt5.QtWidgets import QApplication, QWidget, QDialog class Ui_MainWindow(QDialog): def __init__(self, MainWindow): super(Ui_MainWindow, self).__init__() #много кода self.buttons = QtWidgets.QHBoxLayout() self.buttons.setObjectName("buttons") self.buttonBox = QtWidgets.QDialogButtonBox(self.centralwidget) self.buttonBox.setEnabled(True) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.buttonBox.sizePolicy().hasHeightForWidth()) self.buttonBox.setSizePolicy(sizePolicy) self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Save|QtWidgets.QDialogButtonBox.Apply|QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok) self.buttonBox.button(QtWidgets.QDialogButtonBox.Ok).clicked.connect(self.accept) self.buttonBox.button(QtWidgets.QDialogButtonBox.Cancel).clicked.connect(self.reject) # self.buttonBox.accepted.connect(QDialog.accept) # self.buttonBox.rejected.connect(QDialog.reject) # QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("accepted()"), AboutDialog.accept) # QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("rejected()"), AboutDialog.reject) # buttonBox.accepted.connect(self.accept) # buttonBox.rejected.connect(self.reject) # self.buttonBox.accepted.connect(self.accept) # self.buttonBox.rejected.connect(self.reject) self.buttonBox.setObjectName("buttonBox") self.buttons.addWidget(self.buttonBox) #много кода This dialog is called from another widget by pressing a button.
acceptandrejectslots are executed. If you need to get the result of executing this dialog, then check the return value of theUi_MainWindow.exec_()function at the call site. - aleks.andracceptandrejectslots are executed. If you need to get the result of executing this dialog, then check the return value of theUi_MainWindow.exec_()function at the call site. - aleks.andr