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. Loading QML Components in a ListModel
Forum Updated to NodeBB v4.3 + New Features

Loading QML Components in a ListModel

Scheduled Pinned Locked Moved QML and Qt Quick
24 Posts 4 Posters 24.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.
  • X Offline
    X Offline
    xsacha
    wrote on last edited by
    #21

    Ok, I have fixed the issue. It's in the Main.qml:

    @onReleased: {
    if (grid.firstIndexDrag != -1)
    {
    var moveTo = grid.indexAt(mouseX, mouseY)
    if (moveTo > grid.firstIndexDrag)
    widgetModel.move(moveTo,grid.firstIndexDrag,1)
    else
    widgetModel.move(grid.firstIndexDrag,moveTo,1)
    grid.firstIndexDrag = -1
    }
    }@
    Works with 9 objects, 3 objects and your loader code now. It was just the method I was using to test it that was flawed. Dragging items up rather than down ;).

    If the location being moved to is larger, the position of the previous item has its index change before the action can be performed. Delayed movement would remove this issue.

    The above code works too, though.

    • Sacha
    1 Reply Last reply
    0
    • K Offline
      K Offline
      kyleplattner
      wrote on last edited by
      #22

      You're incredible. Works perfectly.

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kyleplattner
        wrote on last edited by
        #23

        Here is one more stretch:

        If my QML items are being loaded into my Gridview from a model:

        @ListModel {
        id: widgetdelegate
        ListElement {
        element: "WidgetLargeYield.qml"
        value: "test"
        }
        ListElement {
        element: "WidgetLargeMoisture.qml"
        }
        ListElement {
        element: "WidgetLargeWeight.qml"
        }
        }
        @

        Each one of those .qml elements has a text property alias. How do I pass on the value? Through the model or through the page with the gridview?

        1 Reply Last reply
        0
        • X Offline
          X Offline
          xsacha
          wrote on last edited by
          #24

          Well there are a few options.
          Through model:
          @ListElement {
          element: "WidgetLargeYield.qml"
          text: "Test"
          }@
          This can be referenced in GridView/Delegate

          Through GridView as you said.

          Also through the QML files and the delegate:
          In WidgetLargeYield.qml:
          @property string text: "Test"@
          A lonevariable

          OR

          @property alias text: TextEdit.text@
          An alias to a member property

          Then, inside your delegate:
          @ Loader { id: myLoader; source: element }@
          You can now reference the text variable with myLoader.text in GridView, delegate and the widget QML file.

          • Sacha
          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