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 to get a Children of a Component
Forum Updated to NodeBB v4.3 + New Features

How to get a Children of a Component

Scheduled Pinned Locked Moved QML and Qt Quick
12 Posts 3 Posters 19.2k 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.
  • ? This user is from outside of this forum
    ? This user is from outside of this forum
    Guest
    wrote on last edited by
    #1

    I have a ListView, wich loads for the delegate a separate QML component.

    @
    Component {
    id: com

    Item {
    id: it

    Image {
    id: img
    ...
    }
    
    Text {
    id: txt
    ...
    }
    

    }
    }
    @

    Now I want to define some Transitions for one Element (scale of img for example) of the component, but i can not get the Item id or com.children.

    Or is there anonther possibility in QML to define Transitions by switching the center element in a Listview?

    I'm using Qt 5 Alpha and QtQuick 2. Only QML, no C++.

    Can anyone help me?

    Thank You.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      MartinJ
      wrote on last edited by
      #2

      To access the items in the delegate you will need to expose them in the delegate's root object, e.g. using an alias:

      @
      Component {
      id: com

        Item {
          id: it
          property alias image: img
          property alias text: txt
       
          Image {
          id: img
          ...
          }
       
          Text {
          id: txt
          ...
          }
       
        }
      }
      

      @

      1 Reply Last reply
      0
      • ? This user is from outside of this forum
        ? This user is from outside of this forum
        Guest
        wrote on last edited by
        #3

        Hi, thank You for Your answer.

        I know the method with property alias, but then I have to create a property alias in Component.
        But then i get the error - Component objects cannot declare new properties -.

        When i get access to Item, then i can use it.children, too.

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

          Can't you do the transition in the Item itself, based on a property set in the model or the current item or something like that?

          BonganiB 1 Reply Last reply
          0
          • ? This user is from outside of this forum
            ? This user is from outside of this forum
            Guest
            wrote on last edited by
            #5

            I tried this, too. I can define States and Transitions, but then my problem is that I can not call this state of the item because i get no access to the children oh the Component.

            1 Reply Last reply
            0
            • ? This user is from outside of this forum
              ? This user is from outside of this forum
              Guest
              wrote on last edited by
              #6

              Hi,

              I'm using Qt 5 Alpha, QtQuick 2 and want to define Transitions when I switch the CurrentIndex (not the highlight) of a ListView.
              The delegate of the ListView contains a Img and I want to scale it while changing.

              Is this possible?

              Thank You.

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

                I'm sorry, I must have been unclear.

                Why don't you add the appropriate roles to the model itself, and use that to trigger the transitions?

                Perhaps you should try to explain a bit more about why you think you need to have this access (which you will not get). What effect do you want to achieve?

                Edit:

                [quote author="Gihu" date="1340970210"]Hi,

                I'm using Qt 5 Alpha, QtQuick 2 and want to define Transitions when I switch the CurrentIndex (not the highlight) of a ListView.
                The delegate of the ListView contains a Img and I want to scale it while changing.

                Is this possible?
                [/quote]
                Just use the isCurrentItem attached property of the delegate to determine the size of the image, and use a behavior to make an animation of that change.

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

                  [quote author="Gihu" date="1340970210"]Hi,

                  I'm using Qt 5 Alpha, QtQuick 2 and want to define Transitions when I switch the CurrentIndex (not the highlight) of a ListView.
                  The delegate of the ListView contains a Img and I want to scale it while changing.

                  Is this possible?

                  Thank You. [/quote]

                  moderators note: I have merged in the above posting, that was posted as a separate topic. It really looks to me as if this is on the same problem. Please don't open multiple topics on the same problem.

                  1 Reply Last reply
                  0
                  • ? This user is from outside of this forum
                    ? This user is from outside of this forum
                    Guest
                    wrote on last edited by
                    #9

                    That is right. Sorry.

                    I'm now trying, to use State/Transition in the ListView model, that works.

                    But first I tried only to change the property of one Element of the ListViews Component, so i needed access to the components children.

                    Is this the only possibility to add Transitions between switching the ListViews CurrentIndex?

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

                      If you want to trigger something like this from outside of the listview & delegates themselves, you'll have to resort to modifying the model itself. You can add a role in the model that you can use to trigger a change like you want. Then, from the outside, you can modify the item you want.

                      However, for the case you are describing, the original solution sounds much simpler.

                      All in all, you have to realize that from outside the list view, you have no direct access to your delegates, but your delegates can access other QML items.

                      1 Reply Last reply
                      0
                      • ? This user is from outside of this forum
                        ? This user is from outside of this forum
                        Guest
                        wrote on last edited by
                        #11

                        Thank You for your answers.

                        I'm sorry, but I already don't exactly understand how to doit.

                        @ ListView {
                        id: listview_center

                                    model: listmodel_center                 //<-- Is my separate .qml ListView {...}
                                    delegate: component_center         //<-- Is my seperate .qml Component {...}, see the posts before
                        
                                    anchors.fill: parent
                                    orientation: ListView.Horizontal
                                    focus: true
                        

                        }@

                        I set the next Item from the list with this call:

                        @listview_center.positionViewAtIndex(value_menu_center_current,ListView.Center)@

                        I use it so, because I only want to display always one element (without the swaping from the end to the beginning).

                        Can You please explain again how to manage Transtitions/Animations between switch to next Item of the List.

                        Thank You very much.

                        1 Reply Last reply
                        0
                        • A andre

                          Can't you do the transition in the Item itself, based on a property set in the model or the current item or something like that?

                          BonganiB Offline
                          BonganiB Offline
                          Bongani
                          wrote on last edited by
                          #12
                          This post is deleted!
                          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