Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. MultiWindow in QML (proof of concept)

MultiWindow in QML (proof of concept)

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
8 Posts 3 Posters 2.8k Views
  • 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 Offline
    Q Offline
    QKelteseth
    wrote on last edited by
    #1

    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
    0
    • GrecKoG Offline
      GrecKoG Offline
      GrecKo
      Qt Champions 2018
      wrote on last edited by
      #2

      Why do you instantiate a QQmlApplicationEngine for each window ?

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

      Q 1 Reply Last reply
      0
      • GrecKoG GrecKo

        Why do you instantiate a QQmlApplicationEngine for each window ?

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

        Q Offline
        Q Offline
        QKelteseth
        wrote on last edited by
        #3

        @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
        0
        • fcarneyF Offline
          fcarneyF Offline
          fcarney
          wrote on last edited by
          #4

          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
          0
          • fcarneyF fcarney

            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.

            Q Offline
            Q Offline
            QKelteseth
            wrote on last edited by
            #5

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

            fcarneyF 1 Reply Last reply
            0
            • Q QKelteseth

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

              fcarneyF Offline
              fcarneyF Offline
              fcarney
              wrote on last edited by fcarney
              #6

              @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
              0
              • fcarneyF 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?

                Q Offline
                Q Offline
                QKelteseth
                wrote on last edited by
                #7

                @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
                0
                • GrecKoG Offline
                  GrecKoG Offline
                  GrecKo
                  Qt Champions 2018
                  wrote on last edited by
                  #8

                  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
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved