Skip to content
  • Recent
  • Tags
  • Popular
  • SAMSON Connect
  • Get SAMSON
Collapse
SAMSON Forum
  1. Home
  2. Develop
  3. GUI
  4. SBGWindow signals

SBGWindow signals

Scheduled Pinned Locked Moved GUI
9 Posts 2 Posters 8.3k Views
  • 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.
  • YassineY
    YassineY
    Yassine
    wrote on last edited by
    #1

    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
    0
    • StephaneS
      StephaneS
      Stephane
      wrote on last edited by
      #2

      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
      0
      • YassineY
        YassineY
        Yassine
        wrote on last edited by
        #3

        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
        0
        • StephaneS
          StephaneS
          Stephane
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • StephaneS
            StephaneS
            Stephane
            wrote on last edited by Stephane
            #5

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

            1 Reply Last reply
            0
            • YassineY
              YassineY
              Yassine
              wrote on last edited by
              #6

              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
              0
              • StephaneS
                StephaneS
                Stephane
                wrote on last edited by
                #7

                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
                1
                • YassineY
                  YassineY
                  Yassine
                  wrote on last edited by
                  #8

                  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
                  0
                  • StephaneS
                    StephaneS
                    Stephane
                    wrote on last edited by
                    #9

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

                    1 Reply Last reply
                    0

                    Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                    Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                    With your input, this post could be even better 💗

                    Register Login
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Recent
                    • Tags
                    • Popular
                    • SAMSON Connect
                    • Get SAMSON