View Full Version : How to change weekends red color in QCalendarWidget?

29th September 2009, 18:53
Hi all!

Is there any way to change red color of weekeneds (Sunday, Saturday) in the QCalandarWidget to some another color? Of cause, I can override PaintCell() and draw the according dates myself, but it does not help to customize color of the short day names ("Sat" and "Sun") in the horizontal header. I noticed, that Qt always set the QCalendarDelegate's Qt::ForegroundRole value as a Palette::Text every time, it needs to use a red color for drawing. But QCalendarDelegate, used by Qt inside QCalendarWidget, is hidden from the user and I don't know how to access and customize it. Is there any solution from this issue?

Thanks in advance.

30th September 2009, 08:51
You can change the color of the days in a QCaelndarWidget so:

QTextCharFormat format = calendarWidget->weekdayTextFormat(Qt::Saturday);
format.setForeground(QBrush(Qt::white, Qt::SolidPattern));

calendarWidget->setWeekdayTextFormat(Qt::Saturday, format);

First i take the existing format for the specified week day, then i set a different brush and set the modified format back to the needed day. This modifies the name of the day and also the date.

Hope it helps you.

15th March 2011, 11:50
Thanks! :)