MultiWindow in QML (proof of concept)
-
i all,
Repo: https://gitlab.com/kelteseth/qmlmultiwindow
This implementation lets you create a new window with a reference to your C++ class (A simple object list model is used in this example. You could use any QObject inherited class with the ObjectName set!). The goal is here to recreate the functionality of drag and drop widgets like in Krita, where one can easily drag and drop windows in and out of the main window. This is useful to utilize all available monitors for example. For simplicity, we use a simple button to create a new window instead of drag and drop.
It would be greatly appreciated if you have any suggestions on how to improve this concept or point out any flaws!
-
Why do you instantiate a
QQmlApplicationEngine
for each window ?You could create your windows in QML without c++.
-
@GrecKo Yes you could but the main concept here to replicate the windows to mirror their functionality. Because they both use the same c++ object for their data all the connections made in c++ would still be valid. So for example if one has a color picker in a painting software, this color picker have an event
colorPicked(QColor color);
connected to your canvas in C++.
Now if you want to have your color picker in a separate window you could just clone the color picker in a new window without the hassle of setting up with it state and connections :) -
Well, with this method you are creating isolated contexts for each window. You could achieve the same thing spawning QML windows or even C++ windows using the same contexts. Do you need separate contexts for some reason?
Also why do you have one window managing all the others? It seems to me that all the windows use the same qml file. Do you intend to use that window as a manager for the other windows?
I don't understand your mirror concept. If you mean the "same objects" as those provided to the context then it would be achieved using the same context and only registering the objects once.
-
@fcarney said in MultiWindow in QML (proof of concept):
Well, with this method you are creating isolated contexts for each window. You could achieve the same thing spawning QML windows or even C++ windows using the same contexts. Do you need separate contexts for some reason?
Can two or more windows share the same qml context?
Also why do you have one window managing all the others? It seems to me that all the windows use the same qml file. Do you intend to use that window as a manager for the other windows?
Yes
I don't understand your mirror concept. If you mean the "same objects" as those provided to the context then it would be achieved using the same context and only registering the objects once.
See my first response :)
-
@QKelteseth said in MultiWindow in QML (proof of concept):
Can two or more windows share the same qml context?
Yes:
int main(int argc, char *argv[]) { QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QGuiApplication app(argc, argv); QQmlApplicationEngine engine; engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); if (engine.rootObjects().isEmpty()) return -1; return app.exec(); }
Opens two identical windows.
I don't understand your mirror concept. If you mean the "same objects" as those provided to the context then it would be achieved using the same context and only registering the objects once.
See my first response :)
I did see that response. I just don't understand it. Is it just the objects provided to the context?
-
@fcarney said in MultiWindow in QML (proof of concept):
@QKelteseth said in MultiWindow in QML (proof of concept):
Can two or more windows share the same qml context?
Yes:
int main(int argc, char *argv[]) { QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QGuiApplication app(argc, argv); QQmlApplicationEngine engine; engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); if (engine.rootObjects().isEmpty()) return -1; return app.exec(); }
Opens two identical windows.
I don't understand your mirror concept. If you mean the "same objects" as those provided to the context then it would be achieved using the same context and only registering the objects once.
See my first response :)
I did see that response. I just don't understand it. Is it just the objects provided to the context?Well picture me amazed :) Thanks i will try it later :D
-
For the root QML file, I would use an
Instantiator
withWindow
delegates instead of managing all the windows in the first one.