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

Adding QQuickView(QWindow) to a QStackedWidget->addWidget(QWidget)



  • hi folks,

    I'm porting code to qt5. Now i came to this block:

    Q: how do i add a QQuickView to a QStackedWidget ? qStackedWidget->addWidget(QWidget *); BUT QQuickView is a QWindow, not a QWidget.

    Q: is it possible to add qqviews to tabs and stackedwidgets like it was possible in qt4.8 ?


  • Moderators

    AFAIK, you have to fall back on QtQuick1 module. With QtQuick2, it may not be possible (I'm not 100% sure, though).



  • I want to deprecate QtQuick 1.

    It should be possible by design with QtQuick2.


  • Moderators

    QtQuick2 uses entirely different graphics stack (OpenGL based SceneGraph) than QWidgets module and QtQuick1 (raster). You can post a question on development mailing list to be absolutely sure. I only use QML2 in a standalone QQuickView, so the issue has never arisen for me (yet).



  • That opengl stuff should be equivalent to embedding a QGLWidget.


  • Moderators

    "should" is the keyword. As far as I remember the discussion, devs from qt-project have tried a lot to make them fit together, but failed. That is why there is a big split between QtGui and QtWidgets now. But as I have mentioned earlier - I'm not sure I remember it all correctly. Ask on dev ML or search it's archive.





  • For anyone reading this, there's a relevant Qt bug that you might want to follow:

    https://bugreports.qt-project.org/browse/QTBUG-25643

    I can confirm that the winddowwidget code (from the comment above) works for QQuickView (as well as the general case) and have updated the bug accordingly. Hopefully this makes it into 5.0.0, since it strikes me as necessary functionality. If not, at least it's small.

    I think the blocker on this was putting QWidgets into a QQuickView, which this doesn't allow you to do. That said, I think you should be able to render QWidgets on top of it with no issue (in case you're using right-click menus, etc).



  • As any solution for this missing feature been included in latest Qt ?



  • No not yet.
    Until now you need to go the way by using the windowwidget workaround

    Update:
    https://codereview.qt-project.org/#change,44285



  • Here is the solution for QT 5.2.1
    You must pre-install Win32OpenSSL

    QQuickView view_main;
    view_main.resize(683, 384);
    view_main.setResizeMode(QQuickView::SizeRootObjectToView);
    view_main.setSource(QUrl("qrc:///res//main_page.qml"));
    //view_main.show();

    QQuickItem *item_main = (QQuickItem*) view_main.rootObject();
    QWindow* main_page = item_main->window();
    QObject *button_logoff = item_main->findChild<QObject*>( "button_logoff" );
    
    if( button_logoff )
        QObject::connect( button_logoff, SIGNAL(clicked()), ms, SLOT( on_button_logoff() ) );
    else
        qDebug() << "button_logoff is NULL";
    
    if( main_page )
    {
        QWidget *container = QWidget::createWindowContainer( main_page );
        stacked_widget->addWidget( container );
    }
    else
       qDebug() << "main_page is NULL";
    

Log in to reply