Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Getting model in delegate with custom QAbstractListModel and QML Repeater
Qt 6.12 LTS is out! See what's new in the release blog

Getting model in delegate with custom QAbstractListModel and QML Repeater

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 3.1k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    Hello,
    I have implemented QAbstractListModel and made my model visible into QML by qmlRegisterType. In QML I have delegate component and I display model data with Repeater component. Now in delegate I need to call some model method (slot), I know that ListView has attached property ListView.view.model which provides you model instance in delegate. But repeater doesn't has such thing. So I have tried to add ModelRole to my QAbstractListModel implementation and have something like this in its data method:
    @ if (role == ModelRole) return QVariant::fromValue<MyModel*>(this);@
    But this doesl not build:-)
    I would like to know if I am able to get a model from Repeater somehow? Is it possible to provide pointer to model instance from data method, and how should I make it so that it would build and work?:-) Or do I have to use ListView? And if so, how can I set ListView to not flick an stay fixed as Repeater does?
    Thanks for your answers!:-)

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      So I found out that I can disable flicking on ListView with interactive property. But still is it possible to provide instance of model class via its data method?

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