Getting QWindow back into parent QWidget from the fullscreen



  • I have an object that subclasses QWindow. I add it into my QMainWindow's layout by wrapping it into QWidget container like this:

    myWinContainer= QWidget::createWindowContainer(myWindow,this);
    vbox->addWidget(myWinContainer);
    myWinContainer->setFixedSize(640,360);
    

    Then there is a fullscreen mode. I tried to set screen mode directly on myWindow (QWindow):

    myWindow->setParent(nullptr);
    myWindow->showFullScreen();
    

    The windows goes full screen all right. But I can't get it back into its widget when exiting from the full screen.

    myWindow->setWindowState(Qt::WindowNoState);
    myWindow->setParent(p);//where p is cached pointer to parent: myWindow->parent()
    myWindow->showNormal();
    

    The window stays detached from the main window.

    Then I tried to do the full screen via myWindow's parent widget (myWinContainer). In this case, every time I am inserting myWinContainer back into its parent :

    vbox->insertWidget(0,myWinContainer);
    

    layout object, it crashes with some deep internal error.


  • Lifetime Qt Champion

    Hi,

    Since you are using layouts, you should first remove your widget from the layout, then do what you want and at the end put the widget back in the layout.

    Hope it helps



  • It doesn't work. No matter what I do when exiting the fullscreen mode, an error thrown:

    Program: D:\Qt\5.9.1\msvc2015_64\bin\Qt5Cored.dll
    Module: 5.9.1
    File: global\qglobal.cpp
    Line: 3049
    ASSERT: "toplevel->windowHandle()" in file kernel\qwindowcontainer.cpp, line 380

    Again,here is what I do when going full screen:

    vbox->removeWidget(myWinContainer);
    myWinContainer->setParent(this,Qt::Tool);//also tried setParent(nullptr)
    myWinContainer->showFullScreen();
    

    And getting back to normal mode:

    myWinContainer->setWindowState(Qt::WindowNoState);
    vbox->insertWidget(0,myWinContainer);
    myWinContainer->showNormal(); //crashes here with above error
    

    I feel like there is a bug at the level of qwindowcontainer.Because no matter what method I call on the QWindow instances owned by myWinContainer, it leads to the crash with the error above


  • Lifetime Qt Champion

    Can you provide a minimal compilable example that shows that behaviour ?



  • Yes,sure.

    Inside MainWindow (QMainWindow):

    myWindow = new MyWindow(); // inherits from QWindow
    myWinContainer= QWidget::createWindowContainer(myWindow ,this);
    myWinContainer->setFixedSize(640,360);
    //layouts:
    vbox = new QVBoxLayout();
    vbox->setAlignment(Qt::AlignHCenter);
    vbox->addWidget(myWinContainer);
    ui->centralWidget->setLayout(vbox);
    

    Slot that enters/exits fullscreen mode for myWinContainer:

        if( myWinContainer->windowState() == Qt::WindowFullScreen )
        {
            myWinContainer->setParent(this);
            myWinContainer->setWindowState(Qt::WindowNoState);
            vbox->insertWidget(0,myWinContainer);
        }
        else
        {
            vbox->removeWidget(myWinContainer);
            //  myWinContainer->setParent(nullptr);//doesn't help either
            myWinContainer->setParent(this,Qt::Tool);
            myWinContainer->showFullScreen();
        }
    

  • Lifetime Qt Champion

    That's not a compilable example.



  • Hey SGaist,Here is a complete runnable program with the problem.Thanks![0_1504612576256_FullScrTest.rar](Uploading 100%)



  • Oops,it appears I don't have enough privilege to upload files. How do I pass the code to you?


  • Qt Champions 2016

    @sasmaster
    Hi
    it dont like some files. ( not for anyone at all )

    If possible use googledrive/dropbox or Github etc.



  • Hmm,indeed, DropBox is the option... Here is the link to the test prog that show the issue:
    https://www.dropbox.com/s/dxow1ye9fo6r1ap/FullScrTest.rar?dl=0

    Thanks.


  • Lifetime Qt Champion

    I don't know whether you are hitting an unusual code path or if there's really a bug. You should check the bug report system to see if there's something related.

    In any case, since you are doing OpenGL with widgets, did you consider using QOpenGLWidget ?

    On a side note, there's QOpenGLWindow that might also interest you.



  • If you check the code you see that the full screen problem error has no relation to OpenGL at all. What I see here is SDK bug. The reason I don't use any sort of widget is because I don't need all the pile of code which comes with QWidget. All I need is a thin GL surface to render to very very fast.So I guess that I need to file a bug?


  • Lifetime Qt Champion

    What I see is that the assert comes from QWindowContainer which for some reason can't get a window handle from the top level widget. Hence my question whether you are hitting an unusual code path using QWindow as you do.

    If you don't want widgets, then why are you using a QMainWindow ?



  • I do need widgets for some UI around the rendering window.
    "Hence my question whether you are hitting an unusual code path using QWindow as you do" - what do you mean by that?


  • Lifetime Qt Champion

    Simply that I don't know whether the top level widget handling works as expected and you are doing something wrong with your QWindow or if in fact you uncovered a use case not handled properly.



  • And therefore I uploaded for you a full program depicting the use case. Have you tested it?


  • Qt Champions 2016

    @sasmaster

    Hi i did run it on win 10, Qt 5.9/Qt 5.5 and
    did have it crash consistently.
    Also i removed much of the openGL code and seems not related to that at all unless
    its some sort of hidden use or something i missed.

    It does smells like a (Qt) bug but I didn't get 100% proof.



  • Hi mrjj. Thanks for your input. If QT CHAMPION says it smells like a bug, then probably it's a bug :)


  • Lifetime Qt Champion

    Yes I did after having to remove some stuff to make it start like @mrjj did.

    Hence you can also mention that the problem appears on macOS 10.12.6.



  • Thanks for collaboration, guys. Submitted a bug:
    https://bugreports.qt.io/browse/QTBUG-63168


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.