I know there’s no support for QCalendarWidget QSS styling but does anyone know some workarounds for changing the color of sections 1 and 2 of the QCalendarWidget? (the light blue for section 1 and white for section 2)

Thanks!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I’ve examined
QCalendarWidgetsource code and found the solution.QCalendarWidgetinternally has a model and a view to display days.QCalendarModelhas aformatForCell(int, int)function that returnsQTextCharFormatfor a given cell. Returning format is the result of mergingQCalendarViewpalette data, a format for current day (saturday and sunday are shown in red) and a format for current date, which can be set usingQCalendarWidget::setDateTextFormatfunction.Actually an item’s background is:
palis aQCalendarView‘s palette;cgis a color group;headeris true when the current cell is a header cell (section 1 in your example)So, all you need is to set your custom palette to that internal
QCalendarView. In the source code we can find thatQCalendarViewobject has a name “qt_calendar_calendarview” which we can use:In my example section 1 will be red and section 2 will be green.
Additionally you can set colors for every color group of you palette to get the widget you like when it’s active, inactive etc.