简体   繁体   中英

QWidget will not close in full screen mode on OS X (Yosemite)

I have a child class of QWidget, and I'm trying to fix a bug where the the window that it is in cannot be programmatically hidden/closed using the QWidget::hide() or close() methods.

Here are some of the things that I tried:

if(widget->isFullScreen())
{
    widget->showNormal();   //Makes the window normal-sized before closing it
    widget->hide();
}

Here's another way I have tried:

if(widget->isFullScreen())
{
    widget->setWindowState(Qt::WindowMinimized);
    widget->hide();
}

I also tried setting up a slot/signal system:

if(netcam->isFullScreen())
{
    connect(this, SIGNAL(fullScreenExited()),
            this, SLOT(onFullScreenExited()));

    widget->showNormal();
    this->fullScreenExited(); //just hides the widget (or closes it) 

}
else
{
    widget->hide();
}

The result every time is that the window freezes and must be closed by hand. My suspicion is that the first showNormal() is happening asynchronously, and the second close()/hide() never successfully executes.

I also tried this, in hopes that it would complete showNormal() before going on to hide()/close():

if(widget->isFullScreen())
    {
        widget->showNormal();
        QApplication::processEvents();
        widget->hide();
    }

THE MAIN QUESTION: Does anybody have any suggestions for how to deal with closing a full screen QWidget from Qt code?

Question that could also help: Is there a way to ensure that things run synchronously?

Thanks!

EDIT: The only way that I got this to work was to call showNormal() further up in the process, which prevents overlap in the execution of showNormal() and hide(). I'll try to remember to come back later and give a good, basic example with a regular QWidget.

I should also add that the window is put into the fullscreen state with the + (full screen) button, which is located at the top of each window in OS X.

This is a known bug .

The workarounds of showNormal() or showMinimized() are not working because the window state change is not synchronous. And a single processEvent() is not enough. You need to wait for the corresponding QEvent::WindowStateChange event to know when the window has fully moved out of fullscreen and can receive a new window state change.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM