February 19, 2013 by Gunnar Sletta | Comments
Qt 5 introduced a new set of OpenGL classes in Qt Gui and a new rendering pipeline for Qt Quick with the scenegraph. As awesome as these are, they were based on the newly introduced QWindow, making it very hard to use them in existing applications.
To remedy this problem, Qt 5.1 introduces the function QWidget::createWindowContainer(). A function that creates a QWidget wrapper for an existing QWindow, allowing it to live inside a QWidget-based application. Using QQuickView or QOpenGLContext together with widgets is now possible.
QQuickView *view = new QQuickView();
...
QWidget *container = QWidget::createWindowContainer(view);
container->setMinimumSize(...);
container->setMaximumSize(...);
container->setFocusPolicy(Qt::TabFocus);
widgetLayout->addWidget(container);
The window container works by forcing the use of native child widgets inside the widgets hierarchy and will reparent the window in the windowing system. After that, the container will manage the window's geometry and visibility. The rendering of the window happens directly in the window without any interference from the widgets, resulting in optimal performance.
As can be seen from the code-snippet above, the container can also receive focus.
This feature covers the use case where an application wants to either port an existing view to either Qt Quick or the new OpenGL classes in Qt Gui. What about the use case where an application's mainview is written with widgets, say QGraphicsView, and the application wants to keep this and rewrite the surrounding UI with Qt Quick? Well, this is doable by keeping the main application QWidget-based and making each of the big UI blocks a QQuickView embedded in its own container.
Enjoy!
Download the latest release here: www.qt.io/download.
Qt 6.8 release focuses on technology trends like spatial computing & XR, complex data visualization in 2D & 3D, and ARM-based development for desktop.
Check out all our open positions here and follow us on Instagram to see what it's like to be #QtPeople.
Feb 26, 2025
We are happy to announce the release of the Qt Tools for Android Studio..
Jan 27, 2025
Qt Gradle Plugin 1.1 (QtGP) is here! If you missed 1.0 release, I..
Jan 23, 2025
We have released Qt AI Assistant to help you in cross-platform software..