Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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



  • 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?


  • Lifetime Qt Champion

    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.
    


  • 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.


  • Qt Champions 2017

    @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().



  • 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.


  • Lifetime Qt Champion

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



  • 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.


  • Lifetime Qt Champion

    What version of macOS are you running ?



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


  • Lifetime Qt Champion

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


Log in to reply