Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved MultiWindow in QML (proof of concept)

    QML and Qt Quick
    3
    8
    1241
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Q
      QKelteseth last edited by

      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!

      alt text

      1 Reply Last reply Reply Quote 0
      • GrecKo
        GrecKo Qt Champions 2018 last edited by

        Why do you instantiate a QQmlApplicationEngine for each window ?

        You could create your windows in QML without c++.

        Q 1 Reply Last reply Reply Quote 0
        • Q
          QKelteseth @GrecKo last edited by

          @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 :)

          1 Reply Last reply Reply Quote 0
          • fcarney
            fcarney last edited by

            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.

            C++ is a perfectly valid school of magic.

            Q 1 Reply Last reply Reply Quote 0
            • Q
              QKelteseth @fcarney last edited by

              @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 :)

              fcarney 1 Reply Last reply Reply Quote 0
              • fcarney
                fcarney @QKelteseth last edited by fcarney

                @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?

                C++ is a perfectly valid school of magic.

                Q 1 Reply Last reply Reply Quote 0
                • Q
                  QKelteseth @fcarney last edited by

                  @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

                  1 Reply Last reply Reply Quote 0
                  • GrecKo
                    GrecKo Qt Champions 2018 last edited by

                    For the root QML file, I would use an Instantiator with Window delegates instead of managing all the windows in the first one.

                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post