SBGWindow signals
-
Hi all,
In my element I am creating SBGWindow from QWidgets and I would like to catch their closing signal. Does any one of you know how to do it ?
I already tried to connect to the QWidget closing signal:
SAMSONWindow = SAMSON::addWidget(windowsVector[imageNumber], "RDKit SmilesConverter", SBGWindow::Lockable); QObject::connect(SAMSONWindow, SIGNAL(close()), this, SLOT(saveImage()));But it didn't work because SBGWindow doesn't have close() signal. I think it will be very useful to add it.
Thanks for your help !
Yassine -
If windowsVector[imageNumber] derives from SBGWindowWidget, you have two possibilities:
The first one is to override the SBGWindowWidget::hideEvent(QHideEvent* event) function:
void MyWidget::hideEvent(SBGWindowWidget::hideEvent(QHideEvent* event)) { // do something // call the hideEvent function of the parent class SBGWindowWidget::hideEvent(QHideEvent* event) }The second one is to connect to the shown() signal of the SBGWindowWidget class (hence your derived class):
QObject::connect(windowsVector[imageNumber], SIGNAL(shown(bool)), this, SLOT(saveImage(bool)));When the window is closed, shown(false) is emitted.
-
Thank you Stephane, it works but with the second possibility that you mentioned, shown(false) is also emitted when lock button is pressed. First option is better in that sense.
-
True. For some reason, locking needs the window to be hidden and shown again, so the signal is emitted.
-
By the way, isn't
hideEvent()called when the window is locked as well, for the same reason? -
Actually yes, I didn't test it before but
hideEvent()is also called when the window is locked for the same reason as shown signal. Hmmm I thought it was possible to filter the eventevent->type() == QHideEvent::Hidebut it seems that locking the window and hiding it (meaning closing it) has the same event type. Is it possible to distinguish these two actions ? -
Not at the moment, so I'm adding three signals to
SBGWindowfor 0.7.0:closed(): emitted when the window is closed by the userlocked(bool): emitted when the window is locked or unlockedshown(bool): emitted when the window is shown or hidden
-
Perfect. Oh and maybe a flag to set the locking status of
SBGWindowwhen it isLockable. Thank you Stéphane ! -
Done ;-).
setLockedFlag(bool)andgetLockedFlag()insideSBGWindow.