1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Select a date range using QCalendarWidget in PyQt

Discussão em 'Python' iniciado por Stack, Novembro 27, 2025.

  1. Stack

    Stack Membro Participativo

    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()

    Continue reading...

Compartilhe esta Página