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. How to open a new window in Qt Quick with a mouse area signal ?
Forum Updated to NodeBB v4.3 + New Features

How to open a new window in Qt Quick with a mouse area signal ?

Scheduled Pinned Locked Moved QML and Qt Quick
9 Posts 2 Posters 4.1k Views 1 Watching
  • 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.
  • Y Offline
    Y Offline
    ysing
    wrote on last edited by
    #1

    Hello ,

    I'm developping an application using Qt quick and I'm still at the beginning . I created a personalized buttton and I created a mouse area but I didn't know how to open a new window with the signal onClicked .

    Thanks in advance.

    1 Reply Last reply
    0
    • shavS Offline
      shavS Offline
      shav
      wrote on last edited by
      #2

      Hi,

      Did you use "QtQuick Control Components":http://qt-project.org/doc/qt-5/qtquickcontrols-index.html? If so, it's a simple. All you need to create a window like this:
      @
      Window {
      id: newWindow
      //Other properties
      }
      @

      Than in you onClick signal add code like this:
      @
      newWindow.show();
      @

      The second way (I've used it in my app) is create a window dynamically. You can use some code like this:
      @
      function createWindow(parent)
      {
      try
      {
      var window = null;
      var tmp = Qt.createComponent(<the path to QML file with window source>);
      var options = { "id": "wndId",
      //Others property
      };
      window = tmp.createObject(parent, options);
      if(window !== null)
      {
      return window;
      }

          return null;
      }
      catch(exception)
      {
          console.log("EXCEPTION: "+exception);
          return null;
      }
      

      }
      @

      Use this function:
      @
      var wnd = createWindow(<some parent object>);
      if(wnd !== null)
      {
      wnd.show();
      }
      @

      The parent object is a object where you want to show window. It's maybe the id of main window where is your button.

      If you have any questions let me know I'll try to help you.

      Mac OS and iOS Developer

      1 Reply Last reply
      0
      • Y Offline
        Y Offline
        ysing
        wrote on last edited by
        #3

        Thanks very much shav I will try the first way with QtQuick Controls components other ways I will ask you !!

        1 Reply Last reply
        0
        • Y Offline
          Y Offline
          ysing
          wrote on last edited by
          #4

          Hi shav actually i created a new window(It only contains a white rectangle just to test) in a separate qml file but i didn't know how to make the include in the "main.qml".

          In fact I want to make each new page in a separate qml file so that the work would be more organized.

          1 Reply Last reply
          0
          • shavS Offline
            shavS Offline
            shav
            wrote on last edited by
            #5

            Hi ysing,

            I think will be grade if you use the function which I posted upper. All you need it's add the code to action which must show window.
            @
            var wnd = createWindow(<some parent object>);
            if(wnd !== null)
            {
            wnd.show();
            }
            @

            Could you check this "sample":http://dshav.com/qt_samples/testApp.zip.

            Also you can check the documentation about "Loader":http://qt-project.org/doc/qt-5/qml-qtquick-loader.html. This component of QML give you way load some QML file as a part of main file. But I don't use this component to load window.

            Mac OS and iOS Developer

            1 Reply Last reply
            0
            • Y Offline
              Y Offline
              ysing
              wrote on last edited by
              #6

              Thank you very much for your help shav but my application should be in c++(I'm trying to avoid java) hence I will rewrite the code (since I'm still at the beginning) but with c++ classes and I will integrate qml .

              1 Reply Last reply
              0
              • shavS Offline
                shavS Offline
                shav
                wrote on last edited by
                #7

                [quote author="ysing" date="1407876082"]Thank you very much for your help shav but my application should be in c++(I'm trying to avoid java) hence I will rewrite the code (since I'm still at the beginning) but with c++ classes and I will integrate qml .
                [/quote]

                Hmm.... You can use the QML Plugin. Please check this "link":http://qt-project.org/doc/qt-5/qtqml-modules-cppplugins.html. If you want to create the logic of app on C++ and GUI on QtQuick, then plugin will help to you. In this case you can create GUI to show some datas to user and communicate with user (enter/select datas) and all logic methods (send/received datas to/from servers, calculate something, etc.) will be in C++ classes.

                Mac OS and iOS Developer

                1 Reply Last reply
                0
                • Y Offline
                  Y Offline
                  ysing
                  wrote on last edited by
                  #8

                  Ok , actually I'm reading a tutorial in the qt creator that contains an example with Qt qml c++ .

                  If I found other problems I will definitely ask for help .

                  1 Reply Last reply
                  0
                  • Y Offline
                    Y Offline
                    ysing
                    wrote on last edited by
                    #9

                    Hello ,

                    I would like to ask when should I use the qml register type and when to use the plugin.

                    Actually the concept is new to me and I feel confused and I don't know from where to start.
                    I watched the video of Qt developer days 2011 It is discussing this task it clarified a little bit some concepts but I still find it ambiguous .

                    Thanks in advance.

                    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