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

Get a window back on normal level after put it on top level



  • Hello guys!
    On my window i have a checkbox button that allows me to put the window on top level when it is checked and on normal window when it is unchecked. This is how i am trying to reach that but it is not working.
    Thanks for help!!

        Qt::WindowFlags flags = this->windowflags();
               if(ui->istopLvlcheckBox->isChecked()){
                   flags |= Qt::WindowStaysOnTopHint;
                }else{
                    flags &= ~Qt::WindowStaysOnTopHint;
                }
                this->setWindowFlags(flags);
               this->show();
    

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Can you check the window flag example to see it's working properly ?



  • First of all thanks for your reply. I already tried that example and when I check the <<Window stays top>> checkbox it goes to top level but when I unchecked or check <<Window stays bottom>> checkbox it still says top level.


  • Lifetime Qt Champion

    Which OS/Qt version are you running ?



  • Ubuntu 16.04 LTS
    Qt Creator 4.0.3
    Based on Qt 5.7.0 (GCC 4.9.1 20140922 (Red Hat 4.9.1-10), 64 bit)


  • Lifetime Qt Champion

    That's the Qt Creator version, which one is Qt itself ?

    Also, can you test the same thing with your distribution provided Qt ?



  • I am using Qt 5.7.0.
    I did test it but it is the same result.


  • Lifetime Qt Champion

    Try adding the Qt::X11BypassWindowManagerHint to your calls changing the flags.



  • According to the documentation Qt::X11BypassWindowManagerHint means that the window will be borderless
    and that is exactly what it becomes when I add that flag. The point is when i try to debug the code in my first message like this (qDebug() << windowFlags() ), I have something like this:

    • when the checkbox is checked:
    QFlags<Qt::WindowType>(Window|X11BypassWindowManagerHint|WindowTitleHint|WindowSystemMenuHint|WindowMinMaxButtonsHint|WindowStaysOnTopHint|WindowCloseButtonHint|WindowFullscreenButtonHint) 
    

    --when it is unchecked :

    QFlags<Qt::WindowType>(Window|X11BypassWindowManagerHint|WindowTitleHint|WindowSystemMenuHint|WindowMinMaxButtonsHint|WindowCloseButtonHint|WindowFullscreenButtonHint)
    

    As you can see when it is unchecked there is no WindowStaysOnTopHint flag anymore but i do not know why it is not working.


  • Lifetime Qt Champion

    Might be related to QTBUG-53711



  • Thank for all your replies by the way.


Log in to reply