Working with the calendar widget in PyQt4

  • Hi,

    I'm trying to create a small program that allows my wife to quickly select a date and then select the type of shift she had to work at the hospital. Here's an image:

    The idea is that after she selects a date, a shift, and presses Save, the selected cell of the date is given a certain color to easily indicate that she's already selected a shift for that date. Then she continues to the next one, etc. (Even better would be if she could double-click the date after which a dropdown menu appears in the cell that allows her to select either d (for day), e (for evening), or n (for night), but that is way out of my league) programming-wise).

    Finally, when she presses Excel or PDF, all her hours and irregular hours are displayed in a neat order. I already managed that last part with a boring old python console program. I wanted to spice it up with a fancy GUI and figured a calendar would do nicely.

    But I have no experience whatsoever when it comes to C++, Javascript, etc, and every example of the calendar widget appears to be in those programming languages. I've tried for 4 hours now and I can't seem to figure out how to color the selected cell upon pressing the save button.

    I used the Qt Designer to create the layout and this is the output after using pyuic4: (the file is called
    Then I use this to run the program: (this file is called The Save button is already able to gather the selected date and shift, but now it needs to colorize the selected date as well.

    Can anyone give me a hand or point me to an example that uses Python instead of C++ or Javascript?

    Thank you in advance!

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    From a quick look at QCalendarWidget, you'll likely want to use setDateTextFormat to modify the appearance of a given date.

    Hope it helps

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.