PyQt5 QDateEdit - Removing Maximum Date which user can enter

PyQt5 QDateEdit - Removing Maximum Date which user can enter

In PyQt5, the QDateEdit widget allows the user to enter and edit dates. By default, QDateEdit does not impose any date range, but you can set minimum and maximum dates using the setMinimumDate() and setMaximumDate() methods, respectively.

If you have previously set a maximum date and want to remove that restriction, you can set the maximum date to a far-future date (like QDate(9999, 12, 31)), effectively removing any practical limitation.

Here's how you can do this:

from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QDateEdit from PyQt5.QtCore import QDate class App(QWidget): def __init__(self): super().__init__() self.initUI() def initUI(self): layout = QVBoxLayout(self) self.date_edit = QDateEdit(self) # For demonstration, initially set the maximum date to today self.date_edit.setMaximumDate(QDate.currentDate()) # Later, remove the maximum date restriction self.date_edit.setMaximumDate(QDate(9999, 12, 31)) layout.addWidget(self.date_edit) self.setLayout(layout) self.setGeometry(100, 100, 200, 100) if __name__ == '__main__': app = QApplication([]) window = App() window.show() app.exec_() 

In this example, I first set the maximum date to today's date and then effectively remove the maximum date limitation by setting it to QDate(9999, 12, 31).


More Tags

ajax viewchild append silverlight maven-module laravel-4.2 testing preventdefault uirefreshcontrol python-3.6

More Programming Guides

Other Guides

More Programming Examples