[SOLVED] Select a date range using QCalendarWidget in PyQt


I’m using QCalendarWidget in PyQt to find a single date that a user clicks on from a pop-up calendar. I’d like them to be able to select a range of dates- for example, the 12th to the 17th of November instead of just the 12th.

The QCalendarWidget docs mention NoSelection and SingleSelection. How can I implement a multiple selection?

Here is the code I have now:

def selectDates(self):
    self.dateWindow = QWidget()
    self.cal = QCalendarWidget(self)
    self.hbox = QHBoxLayout()
    self.dateWindow.setGeometry(300, 300, 350, 300)


def showDate(self):
    print "Date picked: ", self.cal.selectedDate()


I don’t think that this is possible.
I’m sure you already considered the fact of adding two calendar widgets or dateEdit widgets (one for the first date of the range and one for the last).
But unless you think you can develop a overriden class, you really should think on that possibility.

Answered By – jonathan.hepp

Answer Checked By – Willingham (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *