PDA

View Full Version : accesing events in another widget



andreime
18th July 2009, 09:08
Hello.. i have a question and i think you can help me.
I have a stacked widget that loads two different widgets.
On each widget i have a button that if i press i want to interchange the two widgets(something like widget1 swap to widget2).
Do you have any advice as to how to acces and figure out that the button was pressed?
The swaping is made in the mainwindow, but the button is in two different widget-classes.
Thank you.

wysota
18th July 2009, 09:39
Use signal and slots with either QSignalMapper or QObject::sender().

For example:

QSignalMapper *mapper = ...
QPushButton *buttonOne = ...
QPushButton *buttonTwo = ...
mapper->setMapping(buttonOne, 0);
mapper->setMappinc(buttonTwo, 1);
connect(buttonOne, SIGNAL(clicked()), mapper, SLOT(map()));
connect(buttonTwo, SIGNAL(clicked()), mapper, SLOT(map()));
connect(mapper, SIGNAL(mapped(int)), stackedWidget, SLOT(setCurrentIndex(int)));

andreime
19th July 2009, 10:02
thank you a lot it solved many problems :D