Is it possible to integrate a QWidget into QML/QtQuick 2.0.
-
The problem I'm facing is the following:
- I have a Qt 5.5 project where I use QML/QtQuick 2.0 for the GUI.
- I want to reuse/integrate a QWidget from another project that does not use qml files.
I got to the point where I can show the widget in a separate window. However I need it to be part of the main window, which is qml. I also have trouble getting events back from the widget.
On blogs I read that it is not possible to integrate a QWidget into QML with QtQuick 2.0.
Can either someone verify this statement or show a solution to integrate a QWidget into QML/QtQuick 2.0.Thanks!
-
@RichardD No. Because pure QML doesnot have any functionality which will understand
QWidget
API's.
It's actually the other way. You can integrate QML inQWidget
based applications.
For eg: have a look at QQuickWidget andQWidget's
createWindowContainer. The recommended one isQQuickWidget
. -
@p3c0 Thanks for the quick response!
I have seen that the other way around is possible, but unfortunately that is not the problem I'm dealing with.I found some examples but they are dated, on a previous version of Qt or use QtQuick 1.0:
http://kunalmaemo.blogspot.nl/2011/07/how-to-display-qwidget-into-qml.html
http://doc.qt.io/qt-4.8/qt-declarative-cppextensions-qwidgets-example.html
The QGraphicsProxyWidget method looks very promising to me.So could you state that with QtQuick 1.0 it was possible and with QtQuick 2.0 it is no longer possible?
If the above statement is true, I wonder why this is no longer possible. I can imagine, that a lot of developers have created custom widgets that they would like to use in new qml based applications. Are the concept that different that there is no workaround to deal with this?
Thanks!
-
@RichardD
QtQuick 2.0
is completely different fromQtQuick 1.0
.QtQuick 1.0
backend was implemented with Qt's Graphics Framework whileQtQuick 2.0
is based on Scene Graph to take advantage of OpenGL.
Now sinceQtQuick 1.0
was based on Graphics Framework the API's likeQGraphicsProxyWidget
could be used out of the box in it. But there is no such functionality inQtQuick 2.0
.
Some references here:- http://blog.qt.io/blog/2013/02/19/introducing-qwidgetcreatewindowcontainer/)
- http://blog.qt.io/blog/2013/02/19/introducing-qwidgetcreatewindowcontainer/#comment-342929
You will need to port some of the functionality toQtQuick 2.0
for eg. usingQQuickPaintedItem
.