QCalendarWidget - changing cells/dates colors

224 views
Skip to first unread message

Zoran Sibinovic

unread,
Oct 17, 2020, 1:21:21 PM10/17/20
to QtContribs
Hi to all,

I try to change a colour of a date and also a date cell background and achieved, as in the example, only this:
...
formater := oDlg:calendarWidget:weekdayTextFormat(Qt_Saturday)
oDlg:calendarWidget:setDateTextFormat(QDate( Year( MyDate ), Month(  MyDate   ), Day( MyDate  )), formater)
...
to colour the cell text with red since in the example is used the format of saturday.

Googling I tried

formater:setForeground( QBrush( QColor( 49,196,98 ) ) )
formater:setBackground( QBrush( QColor( 219,177,38 ) ) )
formater:setBackground( QBrush( Qt_magenta ) )
          
but there is no effect on the date or the cell background either.

The code
formater:setBackground(  Qt_magenta )   
formater:setBackground( 0, QBrush( Qt_green ) )
returns an error on runetime as wrong argument.

Anyone knows what I have missed?
Thanks
Zoran

Francesco Perillo

unread,
Oct 17, 2020, 2:33:50 PM10/17/20
to qtcontribs
did you try qss? 

--
You received this message because you are subscribed to the Google Groups "QtContribs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to qtcontribs+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/qtcontribs/05c7a94c-1033-4bbb-bbd8-14639d80f059n%40googlegroups.com.

Zoran Sibinovic

unread,
Oct 17, 2020, 3:17:10 PM10/17/20
to QtContribs
No

Pritpal Bedi

unread,
Oct 17, 2020, 4:14:41 PM10/17/20
to QtContribs
Hi Zoran

This should work:

formater := oDlg:calendarWidget:weekdayTextFormat( Qt_Saturday )
formater:setBackground(  QBrush( QColor( Qt_magenta ) )  )  

oDlg:calendarWidget:setDateTextFormat( QDate( Year( MyDate ), Month(  MyDate   ), Day( MyDate  )), formater )



Pritpal Bedi
a student of software analysis & concepts

Zoran Sibinovic

unread,
Oct 18, 2020, 2:28:48 AM10/18/20
to QtContribs
Yes, it worked thanks a lot!
Reply all
Reply to author
Forward
0 new messages