To add a slot to the button, such as “OK”, using Dialog Button Box?
Answer 1, Authority 100%
-
You can use the method
QDialogButtonBox :: buttons ()
, which will return a list of all the dialog buttons, search for the desired slot and bind to its signal. -
You can use the method
QDialogButtonBox :: button (StandardButton)
, which passed the “type” button as an argument. Call the result is a pointer to the button. -
You can add a button to the button-box yourself using one of the overloaded methods
addButton
: -
But the most correct method would not use something that developers did not anticipate. If you need to “scratch out” button of the dialog, then you have a problem with the architecture or the design. If you want special behavior specific button, you need to create a single button. Or use the provided interface button-box – it slots:
-
accepted ()
(fired when pressed with the role ofAcceptRole
orYesRole
); -
clicked (QAbstractButton *)
(called the dialogue by pressing any button, the pointer on the button will be transmitted as a signal parameter); -
helpRequested ()
(called when the button is clicked with the role ofHelpRole
); -
rejected ()
(called when the button is pressed, the role of theRejectRole
orNoRole
).
-
Answer 2
For example, ‘ok’ button:
self.button_ok = self.buttonBox.button (QtWidgets.QDialogButtonBox.Ok)
self.button_ok.clicked.connect (self.open_new_dialog)
For example ‘retry’ button:
self.button_retry = self.buttonBox.button (QtWidgets.QDialogButtonBox.Retry)
self.button_retry.clicked.connect (lambda: self.end_dialog (0))