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] QAbstractListModel and QML considerations
Forum Updated to NodeBB v4.3 + New Features

[Solved] QAbstractListModel and QML considerations

Scheduled Pinned Locked Moved QML and Qt Quick
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.
  • O Offline
    O Offline
    octal
    wrote on last edited by
    #1

    Hi folks,

    I am currently trying to design a « CalendarView » in QML, with a C++-side QAbstractListModel.
    However, I'm facing an issue, and don't know how to fix it. Here is a screenshot of what I'm trying
    to achieve :

    !http://i.imgur.com/q8vsq.png(Calendar)!

    As you can see, my view consist in a simple GridView, populated by a C++ CalendarModel, which
    is a subclass of QAbstractListModel, defining the following roles :

    @enum Role { DayNumberRole = Qt::UserRole + 1, MonthNumberRole, MonthNameRole, DateRole };@

    This is working fine, however, I don't know how to expose the « items » (the green rectangles) into
    my QML View. I tried returning a QList<CalendarItem *> on my data() function, bound to a given role
    (like ItemsRole), but didn't succeed to.

    What is the best way to do it ? I would like to keep the model-view driven architecture, keeping a
    C++-side model, populated by the user and then a QML view displaying all the datas.

    1 Reply Last reply
    0
    • O Offline
      O Offline
      octal
      wrote on last edited by
      #2

      I finally figured out by myself how to solve my problem.

      As I said, for the « ItemsRole » role on my data() function, I am now returning a simple QList<QObject *> (which is, actually, a QList of CalendarItem *), which I am using as a model QML-side.

      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