Reputation:
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()
Upvotes: 1
Views: 7095
Reputation: 125
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
.
Upvotes: 1
Reputation: 1643
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.
Upvotes: 0