I'm using a QDateEdit to choose a specific date, but I would like to disbale weekends, I only want to choose week days.
self.date = QDateEdit(calendarPopup = True)
self.date.setDisplayFormat("dd-MM-yyyy")
self.date.setMinimumDate(QDate(2021,10,1))
self.date.setDate(QDate(datetime.today()))
QCalendarWidget only allows a single range of accepted dates, and all dates in that range can be selected.
The only solution I could think of (except for creating your own calendar from scratch) is to subclass QCalendarWidget, access the underlying QTableView (which is what shows the calendar) and do the following:
NoSelection;dateForIndexto retrieve the displayed date at a specific index of the table;SingleSelectionwhenever the index at the mouse position is in work days, otherwise set it back toNoSelection;The only issue with this implementation is that if the
dateEditEnabledis set (which is the default), there's no way to prevent selecting weekend days, except from connecting to theactivatedandselectionChangedsignals and eventually reset the selected date to a valid day.