Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Is there an event on QWidget to detect when a windows exits fullscreen (ie by calling showNormal)?

Is there an event on QWidget to detect when a windows exits fullscreen (ie by calling showNormal)?

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 3 Posters 2.6k 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.
  • M Offline
    M Offline
    Michael A. Leonetti
    wrote on last edited by
    #1

    On MacOS my program uses showFullscreen to go into fullscreen mode and after that I want to hide it directly after it exits fullscreen mode. If I call showNormal() or setWidowState( windowState()&~Qt::WindowFullScreen ) and then hide() directly after, the window does exit full screen but doesn't hide.

    Is there a way to detect when fullscreen is done being exited so I can hide the window? Or even hide the window straightaway from fullscreen?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      In the documentation of QWidget::setWindowState, it's mentioned that you can use QEvent::WindowStateChange.

      Excerpt:

      When the window state changes, the widget receives a changeEvent() of type QEvent::WindowStateChange.
      

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • M Offline
        M Offline
        Michael A. Leonetti
        wrote on last edited by
        #3

        Hello! Thank you for responding.

        I should have mentioned that the documentation is correct in this regard. I have this in my code:

        void Video::changeEvent( QEvent *event )
        		{
        			if( event->type()==QEvent::WindowStateChange and !(windowState()&Qt::WindowFullScreen) )
        			{
        				LOG_TRACE( logger() ) << "Hiding window.";
        
        				hide();
        			}
        		}
        

        But it gets called too early and the window doesn't hide. I'm assuming because MacOS is still animating taking the window off of fullscreen mode?

        I can use a timer with an arbitrary amount of seconds (like 5) and it completes the hide. I was just wondering if there was a more streamlined way.

        kshegunovK 1 Reply Last reply
        0
        • M Michael A. Leonetti

          Hello! Thank you for responding.

          I should have mentioned that the documentation is correct in this regard. I have this in my code:

          void Video::changeEvent( QEvent *event )
          		{
          			if( event->type()==QEvent::WindowStateChange and !(windowState()&Qt::WindowFullScreen) )
          			{
          				LOG_TRACE( logger() ) << "Hiding window.";
          
          				hide();
          			}
          		}
          

          But it gets called too early and the window doesn't hide. I'm assuming because MacOS is still animating taking the window off of fullscreen mode?

          I can use a timer with an arbitrary amount of seconds (like 5) and it completes the hide. I was just wondering if there was a more streamlined way.

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by
          #4

          @Michael-A.-Leonetti said in Is there an event on QWidget to detect when a windows exits fullscreen (ie by calling showNormal)?:

          I can use a timer with an arbitrary amount of seconds (like 5) and it completes the hide. I was just wondering if there was a more streamlined way.

          Perhaps something like this:

          QMetaObject::invokeMethod(this, &QWidget::hide, Qt::QueuedConnection);
          

          instead of hide().

          Read and abide by the Qt Code of Conduct

          1 Reply Last reply
          0
          • M Offline
            M Offline
            Michael A. Leonetti
            wrote on last edited by
            #5

            Thank you for your suggestion. I've changed the code to:

            	void Video::changeEvent( QEvent *event )
            	{
            		if( event->type()==QEvent::WindowStateChange and !(windowState()&Qt::WindowFullScreen) )
            		{
            			LOG_TRACE( logger() ) << "Hiding window.";
            
            			//hide();
            
            			QMetaObject::invokeMethod( this, &QWidget::hide, Qt::QueuedConnection );
            		}
            	}
            

            And unfortunately it doesn't hide it still.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Did you check whether you get other events between the moment you get this event and the end of the animation ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • M Offline
                M Offline
                Michael A. Leonetti
                wrote on last edited by
                #7

                If I put a

                LOG_TRACE( logger() ) << __PRETTY_FUNCTION__ << ": " << event->type();
                

                At the beginning of the function I get exactly 1 event at the beginning of the animation:

                2019-03-14, 17:31:55.977997: <trace> (0x000000011a3225c0) [GUI Video] virtual void xconnect::gui::Video::changeEvent(QEvent *): 105
                

                What's funny is that if I invoke hide() the child widgets all disappear, but the main widget does not disappear. If I call hide on a timer the main widget will disappear also.

                So this will work:

                // We are normal
                					setWindowState( windowState()& (~Qt::WindowFullScreen) );
                
                					// Queue a timer on hiding
                					QTimer::singleShot( 1000, this, &Video::hide );
                

                I'm just not sure how portable it is on all macs but it will dismiss the window from full screen and the window will hide.

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  What version of macOS are you running ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    Michael A. Leonetti
                    wrote on last edited by
                    #9

                    Now 10.14.1 Mojave as of yesterday evening. Was 10.13 High Sierra when I first started getting this error.

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      Can you share a minimal compilable exemple that shows this behaviour ?

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved