Beyond accept() reject()
-
I have a dialog that includes an array of buttons that I want to trigger various actions. How can the program that calls the dialog determine exactly which button was pressed? Ideally, I'd like any button press to close the dialog and then drop into something similar to a switch/case : button1, do this, button2, do that, button3 do the other... Right now one button is linked to accept() and another to reject(), which is kind of limiting.
-
Accept is an indication that "some" action is to be taken, while reject means the user wants to cancel or "escape" from the dialog/decision entirely.
Having said that all the buttons that "do something" should accept and set some flag to indicate which action was chosen.
You could then check if the dialog was accepted, and if so, enter a switch/case to test the flag and decide which action to take.
Either that or emit custom signals from the buttons clicks. -
Maybe you can make use of "finished()":http://doc.qt.io/qt-5/qdialog.html#finished instead of accepted()/rejected(). Just connect your buttons clicked()-signals to a short lambda (or a normal slot, should you want to avoid that) and you should be fine. A custom enum might be be a good idea, though.
-
Hi,
You might also be interested by the "QDialogButtonBox":http://doc.qt.io/qt-5/qdialogbuttonbox.html class