SAMSON Forum
    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • SAMSON Connect
    • Get SAMSON

    SBGWindow signals

    GUI
    2
    9
    5893
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Yassine
      Yassine last edited by

      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

      1 Reply Last reply Reply Quote 0
      • Stephane
        Stephane last edited by

        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.

        1 Reply Last reply Reply Quote 0
        • Yassine
          Yassine last edited by

          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.

          1 Reply Last reply Reply Quote 0
          • Stephane
            Stephane last edited by

            True. For some reason, locking needs the window to be hidden and shown again, so the signal is emitted.

            1 Reply Last reply Reply Quote 0
            • Stephane
              Stephane last edited by Stephane

              By the way, isn't hideEvent() called when the window is locked as well, for the same reason?

              1 Reply Last reply Reply Quote 0
              • Yassine
                Yassine last edited by

                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 event event->type() == QHideEvent::Hide but 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 ?

                1 Reply Last reply Reply Quote 0
                • Stephane
                  Stephane last edited by

                  Not at the moment, so I'm adding three signals to SBGWindow for 0.7.0:

                  • closed(): emitted when the window is closed by the user
                  • locked(bool): emitted when the window is locked or unlocked
                  • shown(bool): emitted when the window is shown or hidden
                  1 Reply Last reply Reply Quote 1
                  • Yassine
                    Yassine last edited by

                    Perfect. Oh and maybe a flag to set the locking status of SBGWindow when it is Lockable. Thank you Stéphane !

                    1 Reply Last reply Reply Quote 0
                    • Stephane
                      Stephane last edited by

                      Done ;-). setLockedFlag(bool) and getLockedFlag() inside SBGWindow.

                      1 Reply Last reply Reply Quote 0
                      • First post
                        Last post