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. Using C++ model for MonthGrid in calendar
Forum Updated to NodeBB v4.3 + New Features

Using C++ model for MonthGrid in calendar

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
5 Posts 2 Posters 439 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.
  • B Offline
    B Offline
    bidjiz
    wrote on last edited by
    #1

    Hi everyone, I'm trying to implement a C++ based model for calendar. My Qt version is 6.6. According to Qt documentation calendar should look like this:

    ColumnLayout {
         
            MonthGrid {
    
                month: root.month
                year: root.year
    
                delegate: DayDelegate {}
            }
    }
    

    Nice and simple. Hovewer, I wanted to use a C++ model for MonthGrid. But it does not have any model property. To clarify - I have some data (basically it's more like a log) in tree model. I wanted to create a proxy to pass this data to calendar view and use in DayDelegate. It would be the most elegant way to provide data for calendar in my opinion. Is it even possible?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      ankou29666
      wrote on last edited by
      #2

      So if I understand it right, you want to show inside a MonthGrid the days for which you have data to log ?

      B 1 Reply Last reply
      0
      • A ankou29666

        So if I understand it right, you want to show inside a MonthGrid the days for which you have data to log ?

        B Offline
        B Offline
        bidjiz
        wrote on last edited by
        #3

        @ankou29666 Almost. I want to show all calendar, but I want to highlight days with data, e.g. add background color, add some icons maybe. I can certanly do it without model, but for this I will have to iterate through all data tree, as these elements are not sorted by date.

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

          I would try something like

          Item
          {
              id: root
          
              YourModel
              {
                   id: dataModel
                   // should provide a bool dataForDate(date) method
              }
          
              MonthGrid
              {
                  id: monthGrid
                  delegate: Text 
                  {
                      required property var model
          
                      horizontalAlignment: Text.AlignHCenter
                      verticalAlignment: Text.AlignVCenter
                      opacity: model.month === control.month ? 1 : 0
                      text: model.day
                      font: control.font
                      color: dataModel.hasDataForDate (model.date) ? "green" : "red"
                  }
              }
          }
          
          

          The model for the MonthGrid's delegate is the MonthGrid, not your data model.
          Of course with this example your model would have to provide a function accepting a date as parameter returning a boolean whether or not there's information for that date. The delegate used must also have access to your model.

          I don't know whether you wrote your model in C++ or QML, but especially in the first case, keep in mind that in Qt/C++, date and time are completely distinct types (QDate and QTime, and QDateTime combining both). The dirty trick of javascript is there's only a Date object that combines date and time.
          In other words, JS's Date is equivalent to Qt's QDateTime. This caused me a few issues.
          So the three parameters (day, month, year) version might be an option to consider.

          1 Reply Last reply
          0
          • B Offline
            B Offline
            bidjiz
            wrote on last edited by
            #5

            Thank you, it's an interesting idea! I will give it a try.

            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