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] How to define a custom group property?

[solved] How to define a custom group property?

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

    This page in the documentation http://qt-project.org/doc/qt-5/qtqml-syntax-objectattributes.html explains how to instantiate group properties (e.g. anchors{...}). It is silently about how to create your own grouped property, though.

    This QtBug page https://bugreports.qt-project.org/browse/QTBUG-15269 has been closed and states that apparently it is now possible to create your own grouped property. The question is: how???

    EDIT: For clarification: I basically want to transform this QML code snippet:

    @
    property string recName;
    property int recSomeValue;
    property bool recSomeFlag;
    @

    to something like this:

    @
    property group rec
    {
    string name;
    int someValue;
    bool someFlag;
    }
    @

    This syntax is completely fancied up. How do I write this in syntactically correct QML?

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dasRicardo
      wrote on last edited by
      #2

      It's not directly what you want but a workaround: "here...":http://qt-project.org/forums/viewthread/46913/

      **Sorry for my english :)

      PLEASE ADD [SOLVED] TO YOUR THREAD TITLE IF IT'S SOLVED.**

      1 Reply Last reply
      0
      • D Offline
        D Offline
        digorydoo
        wrote on last edited by
        #3

        Sure. That's how I worked it around; you linked to one of my own questions. :) However, grouping actual properties and having a JavaScript object that contains data is not the same! For instance, properties emit a onBlahChanged signal when their value change, while there is no such mechanism for the members of a JS object AFAIK.

        So, it would really be nice if there was a way to create custom group properties! Is it not possible then?

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dasRicardo
          wrote on last edited by
          #4

          First sorry for that :) Another way, you can create your own group properties class. Create a class from QObject and register it as Qml Type. Now you can use your custom type as property type. The problem this is easy if you have fix properties because you can register it with Q_PROPERTY makro. If you want dynamic properties you need to handle it by your own. See an example "here...":http://qt-project.org/doc/qt-5/properties.html

          **Sorry for my english :)

          PLEASE ADD [SOLVED] TO YOUR THREAD TITLE IF IT'S SOLVED.**

          1 Reply Last reply
          0
          • D Offline
            D Offline
            digorydoo
            wrote on last edited by
            #5

            Hmm, ok, that might work. I hoped it would be simpler, though.

            1 Reply Last reply
            0
            • D Offline
              D Offline
              dasRicardo
              wrote on last edited by
              #6

              Hey, another idea. I'm not at home so i can't test it but what if you make something like this:
              @
              Retangle {
              property Item rec: Item {
              property string recName: "" //for initialization
              property int recSomeValue: 0 //for initialization
              property bool recSomeFlag 0 //for initialization
              }
              rec.onrecNameChanged: {
              console.log("yeah, it's changed");
              }
              rec.recName: "bla"
              }
              @

              **Sorry for my english :)

              PLEASE ADD [SOLVED] TO YOUR THREAD TITLE IF IT'S SOLVED.**

              1 Reply Last reply
              0
              • D Offline
                D Offline
                digorydoo
                wrote on last edited by
                #7

                Interesting idea! I'll check that out!

                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