Results 1 to 3 of 3

Thread: How to change weekends red color in QCalendarWidget?

  1. #1
    Join Date
    Aug 2009
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default How to change weekends red color in QCalendarWidget?

    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.

  2. #2
    Join Date
    Apr 2008
    Location
    Cluj-Napoca, Romania
    Posts
    10
    Thanks
    5
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to change weekends red color in QCalendarWidget?

    Hello,
    You can change the color of the days in a QCaelndarWidget so:

    Qt Code:
    1. QTextCharFormat format = calendarWidget->weekdayTextFormat(Qt::Saturday);
    2. format.setForeground(QBrush(Qt::white, Qt::SolidPattern));
    3.  
    4. calendarWidget->setWeekdayTextFormat(Qt::Saturday, format);
    To copy to clipboard, switch view to plain text mode 

    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.

  3. The following 2 users say thank you to tituslup for this useful post:

    Dimon (30th September 2009), nadineplusv (15th March 2011)

  4. #3
    Join Date
    Mar 2011
    Posts
    1
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Windows Symbian S60

    Default Re: How to change weekends red color in QCalendarWidget?

    Thanks!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.