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 works "property Item ufo: ufo" in root?
Forum Updated to NodeBB v4.3 + New Features

How works "property Item ufo: ufo" in root?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 351 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.
  • J Offline
    J Offline
    Josz
    wrote on last edited by Josz
    #1

    Hi all,

    I have the next code:

    import QtQuick 2.11
    import QtQuick.Window 2.11
    
    Window {
        id: root
        visible: true
        width: 640
        height: 480
        title: qsTr("Ovni")
    
        property int duration: 3000
        property Item ufo: ufo           //How works this here?
    
        Image {
            anchors.fill: parent
            source: "img/ufo_background.png"
        }
    
        ClickableImageV3 {
            id: ufo
            x: 20; y: root.height - height
            source: "img/ufo.png"
            onClicked: anim.restart()
        }
    
        ParallelAnimation {
            id: anim
            NumberAnimation {
                target: ufo
                properties: "y"
                to: 20
                duration: root.duration
            }
            NumberAnimation {
                target: ufo
                properties: "x"
                to: 160
                duration: root.duration
            }
        } //ParallelAnimation
    
    }//root
    
    

    Please, anybody so kind to explain me how works "property Item ufo: ufo" in root? The program works anyway if I delete it. Which is then the purpose?

    Thanks in advance

    sierdzioS 1 Reply Last reply
    0
    • J Josz

      Hi all,

      I have the next code:

      import QtQuick 2.11
      import QtQuick.Window 2.11
      
      Window {
          id: root
          visible: true
          width: 640
          height: 480
          title: qsTr("Ovni")
      
          property int duration: 3000
          property Item ufo: ufo           //How works this here?
      
          Image {
              anchors.fill: parent
              source: "img/ufo_background.png"
          }
      
          ClickableImageV3 {
              id: ufo
              x: 20; y: root.height - height
              source: "img/ufo.png"
              onClicked: anim.restart()
          }
      
          ParallelAnimation {
              id: anim
              NumberAnimation {
                  target: ufo
                  properties: "y"
                  to: 20
                  duration: root.duration
              }
              NumberAnimation {
                  target: ufo
                  properties: "x"
                  to: 160
                  duration: root.duration
              }
          } //ParallelAnimation
      
      }//root
      
      

      Please, anybody so kind to explain me how works "property Item ufo: ufo" in root? The program works anyway if I delete it. Which is then the purpose?

      Thanks in advance

      sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      @Josz said in How works "property Item ufo: ufo" in root?:

      Please, anybody so kind to explain me how works "property Item ufo: ufo" in root? The program works anyway if I delete it. Which is then the purpose?

      If this is your main.qml, then this line has no purpose and can be safely removed. If it is not your main.qml file, then such declaration can be used to expose an internal item to a parent file (a file which includes the current one as component). For such use, however, it is better to use alias:

      property alias ufo: ufo 
      

      (Z(:^

      J 1 Reply Last reply
      0
      • sierdzioS sierdzio

        @Josz said in How works "property Item ufo: ufo" in root?:

        Please, anybody so kind to explain me how works "property Item ufo: ufo" in root? The program works anyway if I delete it. Which is then the purpose?

        If this is your main.qml, then this line has no purpose and can be safely removed. If it is not your main.qml file, then such declaration can be used to expose an internal item to a parent file (a file which includes the current one as component). For such use, however, it is better to use alias:

        property alias ufo: ufo 
        
        J Offline
        J Offline
        Josz
        wrote on last edited by
        #3

        @sierdzio said in How works "property Item ufo: ufo" in root?:

        your main.qml, then this line has no purpose and can be safely removed. If it is not your main.qml file, then such declaration can be used to ex

        Thank you very much! A nice day.

        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