Home qt Dialog Button Box

Dialog Button Box




To add a slot to the button, such as “OK”, using Dialog Button Box?

Answer 1, Authority 100%

  1. 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.

  2. 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.

  3. You can add a button to the button-box yourself using one of the overloaded methods addButton :

  4. 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 of AcceptRole or YesRole );

    • 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 of HelpRole );

    • rejected () (called when the button is pressed, the role of the RejectRole or NoRole ).

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))

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions