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] Flickable: Items added from C++ not moving
Forum Updated to NodeBB v4.3 + New Features

[solved] Flickable: Items added from C++ not moving

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 2 Posters 1.3k 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
    dsmn
    wrote on last edited by
    #1

    Hi,

    I am trying to add items from a c++ method to a Flickable component. Everything is working so far, but the newly added items don't move when flicking. Items added via qml behave as expected.
    The items from c++ are added statically at the position defined in the code.
    When debugging the c++ items appear as children of the qml Flickable.

    An excerpt from the code:

    @
    QQmlComponent event_component(qmlContext(ui_timeline)->engine(), QUrl("qrc:/Event.qml"));

    int event_count = model_events->rowCount(QModelIndex());
    int timeline_width = (event_count - 1) * window_width + window_width;
    ui_timeline->setProperty("contentWidth", timeline_width);
    
    for(int i=0; i<event_count; i++) {
        QQuickItem *event_view = qobject_cast<QQuickItem*>(event_component.create(qmlContext(ui_timeline)));
        event_view->setParentItem(ui_timeline);
        event_view->setX(130*i);
        event_view->setY(window_height/2 - event_view->height()/2 - 16);
    }
    

    @

    ui_timeline represents the Flickable
    event_view the added items from a qml file

    Is there anything wrong in the way I'm adding the items to Flickable?

    best regards

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi,

      Since you are adding the Items dynamically you should reparent them to Flickable's contentItem.
      You can find the Flickable object in C++ using findChild(), then its first child would be the contentItem.
      Also contentWidth and contentHeight too should be set.

      157

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

        Hi,

        that worked perfectly, thanks!

        1 Reply Last reply
        0
        • p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

          Glad that it worked :)
          You can mark the post as solved by editing the post title and prepend [solved].

          157

          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