PDA

View Full Version : Question about QCalendarWidget with PyQT



hf
15th April 2008, 22:21
Greetings to all:

I'm fairly new to qt, but, I can't imagine going back to gtk anymore. So as a first post, a big thanks to the qt developers.

So, on with my question...

I've been having some problems with the QCalendarWidget, which is very
nice, but seems to lack some documentation. I tried googling and
looking through many mail lists, but still can't find the solution to
my problem. I have the following code:

...
dateStr = "20070101" # january 1, 2007
date = QDate.fromString(dateStr, QString("yyyymmdd"))
calendar.setSelectedDate(date)
...

But, the calendar does not change the month,year, or day. After the
calendar is rendered, the current date is displayed, not the selected
date. I can force it to change the displayed
month and year, but not the day with the following code...

...
calendar.setCurrentPage(2007, 01)
...

If I call the method showSelectedDate, the current day is displayed
instead. Am I actually changing the selectedDate or do I have to do
something else?
Also, what method do I use so that the day(1,2,3...31) is highlighted?
Is there some sort of 'update' method which will redraw the calendar
with the new selectedDate?

Regards,
HF

wysota
15th April 2008, 23:30
Have you checked if date.isValid()?

hf
21st April 2008, 22:40
Wow, thanks, I completely overlooked that. What I found was that the date format should be "yyyyMMdd" instead of "yyyymmdd". Also, for some reason, I could only get the calendar to work right with QDateTime instead of QDate. (I'm sure it's an error on my part) :eek: