简体   繁体   中英

How to restore to window mode when minimized in qt

void test()
{
    if(flag==1)
    {
        qDebug("in if");
        showNormal();
        flag=0;
    }
    else
    {
        qDebug("in else");
        showMinimized();
        flag=1;
    }
} 

I use a QTimer to connect this function. I want it run as this: minimized, sleep 3sec, restore to window mode, sleep 3 sec, minimized....

But the actual result is minimized, sleep 3, do nothing, sleep 3, do nothing, sleep 3, restore to window mode. After minimized, there are two times the function do nothing. How this can happened, and how to fix it?

Assuming your widget is w, then try

w->setWindowState(w->windowState() & ~Qt::WindowMinimized | Qt::WindowActive);

to restore the window, and

w->setWindowState(w->windowState() | Qt::WindowMinimized)

to show the window minimised. You should post more of your code so that we can better understand the problem.

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