'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.cal.clicked[QtCore.QDate].connect(self.showDate)
self.hbox = QHBoxLayout()
self.hbox.addWidget(self.cal)
self.dateWindow.setLayout(self.hbox)
self.dateWindow.setGeometry(300, 300, 350, 300)
self.dateWindow.setWindowTitle('Calendar')
self.dateWindow.show()
def showDate(self):
print "Date picked: ", self.cal.selectedDate()
Solution 1:[1]
Though this is a really old post, but I have still posted how i tackled the problem.
I have used 2 DateEdits, one for fromDate and the other for toDate. If you want to have a calender pop up effect for your DateEdits, set calendarPopUp parameter to True.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Sabbir Talukdar |
