How to get informations in QStyledItemDelegate?
-
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 thatpaint()
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());
-
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.
-
You can set the text format of your cells via QCalendarWidget::setWeekdayTextFormat(). There you can also set the desired background.
-
@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?
-
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.