PDA

View Full Version : Create new signal for derived widget



GadiK
29th December 2009, 10:19
Hi.
I wanted to make a check box widget which could emit a signal with an index whenever it's checked/unchecked.

I made a new class derived from QCheckBox which contains a data member that holds the box's index.

I want to override "stateChanged(int) signal to be "stateChabged(int,int)" so it will contain the index.

I created a new signal in the Qt Designer (using the "edit" button in the Slots\Signals dialog).
I added the overriding definition of the signal to the class header file.

How do I proceed? Does the signal function has to have a body and if so what does it contain?

The Qt assistant documentation is very lacking.

Thank you.

GadiK
29th December 2009, 10:28
Worked out a solution.
Connected the original signal stateChanged(int) to slot animateClick(int).
In the slot definition (.cpp) I emit my overridden signal using:


void QCheckBoxCustom::animateClick(int state)
{
emit stateChanged(index, state); //index is a class data member
}


Is there another way?

numbat
29th December 2009, 11:15
You may be interested in QSignalMapper.

GadiK
29th December 2009, 11:27
Okay, didn't know about that.
Thank you.