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. [solved] Z-order in dynamically created object

[solved] Z-order in dynamically created object

Scheduled Pinned Locked Moved QML and Qt Quick
10 Posts 3 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.
  • Z Offline
    Z Offline
    Zondar
    wrote on last edited by
    #1

    I want to the red rectangle has higher Z value than blue one, but it does not seems it's working between two objects in different files.

    main.qml
    @import QtQuick 2.2
    import QtQuick.Controls 1.1

    ApplicationWindow {
    id: root
    visible: true
    width: 640
    height: 480

    Rectangle {
        color: "red"
        height: 100
        width: 100
        z: 1
    
        Component.onCompleted: {
            var component = Qt.createComponent("rect.qml")
            var object = component.createObject(root)
        }
    }
    

    }@

    rect.qml
    @import QtQuick 2.0

    Rectangle {
    y: 50
    width: 100
    height: 100
    color: "blue"
    z: 0
    }@

    Thank you

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      You are aware you do not need Qt.createComponent() in this case, right?

      Anyway, to answer. Try this:
      @
      Component.onCompleted: {
      var component = Qt.createComponent("rect.qml")
      var object = component.createObject(root)
      object.z = 0;
      }
      @

      (Z(:^

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        Zondar
        wrote on last edited by
        #3

        Yep, I am, it's just the simplest example.
        Your solution doesn't work :-/.

        1 Reply Last reply
        0
        • p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

          Hi,

          If you use Item instead of ApplicationWindow it works as expected. But wondering why it doesn't with ApplicationWindow !!!

          157

          1 Reply Last reply
          0
          • Z Offline
            Z Offline
            Zondar
            wrote on last edited by
            #5

            I tried to replace ApplicationWindow by Item and then by Rectangle, they build and run without problem, but window even doesn't show up.
            My Qt version is 5.2.1

            1 Reply Last reply
            0
            • p3c0P Offline
              p3c0P Offline
              p3c0
              Moderators
              wrote on last edited by
              #6

              Are you using QQmlApplicationEngine to load the QML file ?

              157

              1 Reply Last reply
              0
              • Z Offline
                Z Offline
                Zondar
                wrote on last edited by
                #7

                Yes, I am.

                1 Reply Last reply
                0
                • sierdzioS Offline
                  sierdzioS Offline
                  sierdzio
                  Moderators
                  wrote on last edited by
                  #8

                  In order to show your QML when switching away from ApplicationWindow, you can use QQuickView class.

                  (Z(:^

                  1 Reply Last reply
                  0
                  • Z Offline
                    Z Offline
                    Zondar
                    wrote on last edited by
                    #9

                    It works.
                    Thank you

                    1 Reply Last reply
                    0
                    • p3c0P Offline
                      p3c0P Offline
                      p3c0
                      Moderators
                      wrote on last edited by
                      #10

                      Also another observation, keeping ApplicationWindow if you set the z value of Rect to negative also works as expected.

                      157

                      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