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. Fully understand QML Elements
QtWS25 Last Chance

Fully understand QML Elements

Scheduled Pinned Locked Moved QML and Qt Quick
6 Posts 2 Posters 2.0k 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.
  • G Offline
    G Offline
    godbod
    wrote on last edited by
    #1

    Hello everyone,

    I am new QML and I have been using it for projects following examples given in the documentation. But today I really want to fully understand how it works to better code applications and to know all the possibilities offered to me.
    To answer that question I would like to take the case of the Item class.

    "Item class":http://doc.qt.digia.com/4.7-snapshot/qml-item.html

    One question is : putting Image in Item does mean that the Item is inherited by Image ?
    @
    Item {
    Image {
    source: "tile.png"
    }
    Image {
    x: 80
    width: 100
    height: 100
    source: "tile.png"
    }
    Image {
    x: 190
    width: 100
    height: 100
    fillMode: Image.Tile
    source: "tile.png"
    }
    }
    @

    One more thing is : How come we have a Key property ? where does it come from actually as it doesn't appear in the Item class?

    @
    Item {
    focus: true
    Keys.onPressed: {
    if (event.key == Qt.Key_Left) {
    console.log("move left");
    event.accepted = true;
    }
    }
    Keys.onSelectPressed: console.log("Selected");
    }
    @

    I really need to be able to read any class and do a relevant QML coding and not only examples copies.

    L'imagination est tout, c'est l’aperçu des futures attractions de la vie.

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

      Ad. 1. No. It means that QML engine will assign the Item as parent to the Image. QML components are not "c++" in that regard. What you define in a QML file is the parent-child structure, not inheritance. This is the same as adding widgets to a QMainWindow in QtWidgets - it's all about meta object system and parenting.

      Ad. 2. IIRC, Key is an "attached property":http://qt-project.org/doc/qt-4.8/propertybinding.html#attached-properties. This can be officially labelled as QML Magic.

      (Z(:^

      1 Reply Last reply
      0
      • G Offline
        G Offline
        godbod
        wrote on last edited by
        #3

        Oh thank you ! You're right, I have been trying to see QML Elements like C++ classes.
        Another question could be, how can I know which Element may or may not be parent to another Element ?
        And last but not the least, are there others "MAGIC" mechanisms that a beginner can encounter ?

        L'imagination est tout, c'est l’aperçu des futures attractions de la vie.

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

          Hm, I think all elements can be children of all other elements. One possible exception might be the QtObject element, as it lacks rendering, so putting graphical elements into it may produce an error - but to be honest I don't remember what the result of such an action was.

          If you want to learn, start a new QML project, and write it from ground up - I find it to be the best way to get to know any language. QML is different in it's "philosophy" than C++ or all other imperative languages, so it takes some time to get used to it fully. It is very impressively powerful, though.

          As for the magic... it's all a bit magicky. I can't think of any other mechanism right now, but there sure are lots.

          (Z(:^

          1 Reply Last reply
          0
          • G Offline
            G Offline
            godbod
            wrote on last edited by
            #5

            Thanks a lot for your quick answers Sierdzio.

            L'imagination est tout, c'est l’aperçu des futures attractions de la vie.

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

              Pleasure. Feel free to ask more :)

              (Z(:^

              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