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. State target: object vs type
Forum Updated to NodeBB v4.3 + New Features

State target: object vs type

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

    Hello,

    I am new to QML and was going through the QT Quick introduction training about user interaction, input and states session, provided at Qt website.
    I must say it is nice set of series to introduce the QML and Qt Suite. States seems to be really powerful concept. I was wondering shouldn't it be possible to specify type in target of state rather than object?

    Suppose I have 10 text fields on a dialog and I want a similar behaviour and if I specify only states targeted at each object then there will be tremendous duplication of code, instead I can specify that within this item (dialog) all items of type: textfield should be applied this state.

    Thanks for your answers.

    Best,
    Sarang

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      I am not entirely sure I understand what you mean.

      I think you could do what you want by simply creating your own type (that is, a new file), and make that item reference the parents state, for instance. Something along these lines:

      @
      //file: MyTextField.qml

      TextEdit {
      id: textField
      state: parent.state
      enabled: (state == "TheEnabledState")

      // whaterver else you want in here
      }
      @

      Or am I totally off track here?

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sarangbaheti
        wrote on last edited by
        #3

        Hi Andre,

        Many thanks for replying.
        Actually my point was:

        @TextEdit {
        id: textField1
        state: parent.state
        enabled: (state == "TheEnabledState")

        // whaterver else you want in here
        }

        TextEdit {
        id: textField2
        state: parent.state
        enabled: (state == "TheEnabledState")

        // whaterver else you want in here
        }
        @
        then I will have to create 2 states for two text fields. But If I have 10 such fields in dialog then I may need to write 10 states, if we go by objects.
        What I am asking is it possible to create 10 textfields and associate them with only one state for consistency and maintenance.

        Other option may be to create a separate textfield qml file (is it called component?) and then use it.

        Thanks,
        Sarang

        Edit: please use @ to mark code sections; Andre

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          No, the point was, that you don't need to maintain 10 states. Instead, after defining your own MyTextEdit as explained above, you can simply do:

          @
          MyTextEdit {
          id: TextEdit1;
          }
          MyTextEdit {
          id: TextEdit2;
          }
          @

          The state is automatically managed the same for all instances of MyTextEdit that way.

          1 Reply Last reply
          0
          • S Offline
            S Offline
            sarangbaheti
            wrote on last edited by
            #5

            Ok.

            So the basic philosophy of Qt QML is to create lots of customized components. But then I will have to rename the files and my components accordingly so that I don't have clashes.

            Is there any best practices document about this?

            Thanks!
            Sarang

            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