nabroyan nabroyan - 11 months ago 89
C++ Question

QCalendarWidget selection color

I have a

and some days of month are colored (for example holidays are red). When I select a day which is colored, selection clears the color and I can't see it's original color. But when I deselect that day - color is back. Please see in pictures.

enter image description here

enter image description here

Is there a way to keep color even if a day is selected? I know that there is a way to do this for
with delegates, but I can't find anything like this for
. Any Ideas? Thank you for your time.

Answer Source

You can get access to the internal QTableView object of your calendar widget like this:

QCalendarWidget *c = new QCalendarWidget;

QTableView *view = c->findChild<QTableView*>("qt_calendar_calendarview");
if (view)
    veiw->setItemDelegate(new MySuperCalendarDelegate);

Then you can use a custom delegate that will set proper background and foreground colors.

Also you can check my previous answer on QCalendarWidget styling.