Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to get informations in QStyledItemDelegate?
Qt 6.11 is out! See what's new in the release blog

How to get informations in QStyledItemDelegate?

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 293 Views
  • 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.
  • Q Offline
    Q Offline
    qwe3
    wrote on last edited by
    #1

    Hi,

    I have my own QStyledItemDelegate and reiplementet paint() function on it. I need that delegate to use with my QCalendarWidget. And in standard QCalendarWidget weekend's days ( Saturday, Sunday ) are red. The rest days's color is black. I would like to get that information ( red / black color ) in that paint() function.

    And the second information: I would like to know in paint() function, which day there is. But I need full date ( year, month, day ). The day I can get like this:

    index.data(Qt::ItemDataRole());
    
    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #4

      I don't know why such stuff should be needed but you will need additional information from e.g. QCalenderWidget::currentPageChanged() to retrieve the month and year. Then you know the date and can draw something different for the specific days.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      1
      • Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #2

        You can set the text format of your cells via QCalendarWidget::setWeekdayTextFormat(). There you can also set the desired background.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        1 Reply Last reply
        1
        • Q Offline
          Q Offline
          qwe3
          wrote on last edited by
          #3

          @Christian-Ehrlicher Thank you for your answer, but I think I don't underrstand something.

          I need that color in paint() function like this ( pseudocode ):

             if( dayTextColor == "red")
            {
               painter->drawSomething;
            }
            else if(  dayTextColor == "black")
            {
               painter->drawOtherThing;
            }
          

          And the same with the date.

          Can you explain how to use QCalendarWidget::setWeekdatsTextFormat() to achieve that?

          1 Reply Last reply
          0
          • Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #4

            I don't know why such stuff should be needed but you will need additional information from e.g. QCalenderWidget::currentPageChanged() to retrieve the month and year. Then you know the date and can draw something different for the specific days.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            1 Reply Last reply
            1

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved