PDA

View Full Version : pushbutton action



mickey
20th April 2006, 18:22
Hi, I have linked a button to this SLOT;it's a toggled button in a exclusive toolbar button;
If my button is down and if I click again on it, the putton is down again (OK), but start SLOT and it executes "emit (setEdit(0));" I don't want this; my button is down still; sould it executes the first part of 'if'? Thanks



void MainForm::zoomingIn( bool pressed )
{
if (pressed) {
printf("zoomIN\n");
emit (setEdit(3));
}
else {
emit (setEdit(0));
}
}

wysota
20th April 2006, 19:45
What signal did you connect it to?

mickey
20th April 2006, 21:32
the signal connected to this SLOT is toggled(bool).

wysota
20th April 2006, 23:46
You should probably try with stateChanged(int) signal. This will not trigger the slot if you click on an already depressed button. I guess toggled() shouldn't be emitted too, but looks like it is...

mickey
21st April 2006, 00:05
sorry, but this signal is from Designer; and the possiblity are: toggled(bool) and activated()....??

wysota
21st April 2006, 10:54
I have a stateChanged(int) signal in Designer. You're trying to connect to a slot taking a bool parameter, so Designer hid signals which don't match the signature. Change the slot signature and Designer will show you the stateChanged(int) signal.

mickey
21st April 2006, 16:13
sorry, I have deleted the SLOT from desinger, but when I choose action zoomIn, in the signal appears only two above; I remember that toggleAction on this action is 'true';
don't I undestand?

wysota
21st April 2006, 18:33
The signal surely is there. It's present since Qt 3.0 so it's not the matter of version... You can take a look at the docs: QButton::stateChanged(int). Try some other way of connecting the signal or attach the ui file here and I will make that connection for you.

EDIT: What do you mean "action ZoomIn"? You said you were connecting a button, not an action... I am talking about connecting the button's stateChanged signal to some signal/slot (whatever it is, be it even the action's activated() signal).

mickey
21st April 2006, 19:17
sorry, it isn't a button; is an ACTION!!! (changeState(int) signal there is; but ie for spinBox.....)

wysota
21st April 2006, 19:46
So maybe it's better to connect to the action group directly?

You could use the selected(QAction*) signal then and act upon the action which was chosen.