intercepting button clicks in QDialogButtonBox
I have a QDialogButtonBox with Reset, OK, Cancel buttons. This was created (i.e. put in a dialog windows) using Qt Designer.
To intercept clicks on OK and Cancel buttons is straightforward using accepted() and rejected() signals.
To intercept clicks on the Reset button I have to use the following signal:
void clicked(QAbstractButton * button)
I.e. I can use the following slot (CProgOptions is the class name of my dialog window):
Code:
{
if(button==MYRESETBUTTON){
HERE GOES MY CODE
}
}
My problem is: what should I put in the code instead of "MYRESETBUTTON"?
In other words, where can I find the name of the pointer to the Reset button?
Thanks to anyone that would consider answering.
Re: intercepting button clicks in QDialogButtonBox
Code:
{
HERE GOES MY CODE
}
}
should work fine.
Re: intercepting button clicks in QDialogButtonBox
Alternatively you can use the pointer to the button and directly connect to its clicked() signal.
Cheers,
_
Re: intercepting button clicks in QDialogButtonBox
It works!.
I just had to add a cast and to use ui-> (since I generated the buttonBox inside Qt Designer) as follows:
Code:
HERE GOES MY CODE
}
Thanks again for the help.
Re: intercepting button clicks in QDialogButtonBox
I would recommend avoid using C-style casts in C++ application, its matter of consistency. Use static_cast in this situation,
Re: intercepting button clicks in QDialogButtonBox
And you don't have to cast at all if you connect directly to the button in question :)
Cheers,
_
Re: intercepting button clicks in QDialogButtonBox
It's an old thread, but my internet search turned it up so for other travellers I thought it'd be helpful to translate anda_skoa's suggestion into code:
Code:
...
// in dialog class definition in header file
private slot:
void on_reset_clicked();
...
// in the dialog cpp file:
#include <QPushButton>
...
// in dialog contructor:
connect(ui
->buttonBox
->button
(QDialogButtonBox::Reset),
SIGNAL(clicked
()),
SLOT(on_reset_clicked
()) ...
// and finally the clicked method
void on_reset_clicked()
{
// Your code here
}
Re: intercepting button clicks in QDialogButtonBox
Quote:
Originally Posted by
markwal
It's an old thread, but my internet search turned it up so for other travellers I thought it'd be helpful to translate anda_skoa's suggestion into code:
Code:
...
// in dialog class definition in header file
private slot:
void on_reset_clicked();
...
// in the dialog cpp file:
#include <QPushButton>
...
// in dialog contructor:
connect(ui
->buttonBox
->button
(QDialogButtonBox::Reset),
SIGNAL(clicked
()),
SLOT(on_reset_clicked
()) ...
// and finally the clicked method
void on_reset_clicked()
{
// Your code here
}
markwal, by far the best solution using signals for each!