- PyQt - Home
- PyQt - Introduction
- PyQt - Environment
- PyQt - Hello World
- PyQt - Major Classes
- PyQt - Using Qt Designer
- PyQt - Meta Objects
- PyQt Signals & Slots
- PyQt - Signals and Slots
- PyQt - Support and Signals
- PyQt - Unbound and Bound Signals
- PyQt - New Signals with PyQtSignal
- PyQt - Connecting, Disconnecting, & Emitting Signals
- PyQt - Slot decorator
- PyQt - Slot Connection
- PyQt Layouts
- PyQt - Layout Management
- PyQt - QBoxLayout
- PyQt - QGridLayout
- PyQt - QFormLayout
- PyQt - QHBoxLayout
- PyQt - QVBoxLayout
- PyQt - QStackedLayout
- PyQt - QGraphicsGridLayout
- PyQt - QGraphicsAnchorLayout
- PyQt - QGraphicsLayout
- PyQt - QGraphicsLinearLayout
- PyQt Basic Widgets
- PyQt - Basic Widgets
- PyQt - Qlabel Widget
- PyQt - QLineEdit Widget
- PyQt - QPushButton Widget
- PyQt - QRadioButton Widget
- PyQt - QCheckBox Widget
- PyQt - QComboBox Widget
- PyQt - QSpinBox Widget
- PyQt - QMessageBox
- PyQt - QDialogButtonBox Widget
- PyQt - QFontComboBox Widget
- PyQt - QDoubleSpinBox Widget
- PyQt - QToolBox Widget
- PyQt - QMenuBar, QMenu & Qaction Widgets
- PyQt - QToolTip
- PyQt - QInputDialog Widget
- PyQt - QFontDialog Widget
- PyQt - QDialog Widget
- PyQt - QFileDialog Widget
- PyQt - QTab Widget
- PyQt - QSplitter Widget
- PyQt - QDock Widget
- PyQt - QStatusBar Widget
- PyQt - QTabBar
- PyQt - QList Widget
- PyQt - QScrollBar Widget
- PyQt - QProgressBar
- PyQt - QCalendar Widget
- PyQt - QMessageBox Widget
- PyQt - QPlainTextEdit
- PyQt - QDateEdit
- PyQt - QDateTimeEdit
- PyQt - QTimeEdit
- PyQt - QTextEdit
- PyQt - QTextBrowser
- PyQt - QScrollArea
- PyQt - Drag and Drop
- PyQt - Multiple Document Interface
- PyQt - QDialog Class
- PyQt Views
- PyQt - QColumnView
- PyQt - QTableView
- PyQt Drawing API
- PyQt - Drawing API
- PyQt - Drawing a Line
- PyQt - Drawing a Rectangle
- PyQt - Drawing a Triangle
- PyQt - Drawing a Circle
- PyQt - Drawing a Ellipse
- PyQt - Drawing a Polygon
- PyQt - Geometric Transformation
- PyQt - Drawing Effect
- PyQt Groups
- PyQt - QButtonGroup
- PyQt - QGroupBox
- PyQt Effects
- PyQt - Effects
- PyQt - Opacity Effect
- PyQt - QGraphicsBlur Effect
- PyQt - QGraphicsColorize Effect
- PyQt - QGraphicsDropShadow Effect
- PyQt Events
- PyQt - Event Handling
- PyQt - File Open Event
- PyQt - Action Event
- PyQt - Hide Event
- PyQt - Resize Event
- PyQt Database
- PyQt - Database Handling
- PyQt Essentials
- PyQt - BrushStyle Constants
- PyQt - QClipboard
- PyQt - QPixmap Class
- PyQt Useful Resources
- PyQt - Quick Guide
- PyQt - Useful Resources
- PyQt - Discussion
PyQt - QDateEdit
A QDateEdit is a widget that allows users to input and edit dates. Think of it as a user where we have date picker to choose a specific date.
Imagine we are filling out a form, and there is a field where we need to enter the birthdate. The QDateEdit provides an intuitive way to do that. We can type the date directly using the keyboard or use the arrow keys to increment or decrement the date. It is like adjusting a calendar manually.
Following are some key properties of QDateEdit −
- Date − This property holds the date displayed by the widget. Its the actual date youve selected.
- Minimum Date − We can set the earliest date that users are allowed to choose. For example, if we are booking an appointment, we might want to prevent users from selecting dates in the past.
- Maximum Date − Similarly, We can set the latest date users can pick. May be we are creating a future event scheduler, and we dont want dates beyond a certain point.
- Display Format − We can customize how the date appears in the widget. It could be something like "dd/MM/yyyy".
Properties of QDateEdit
There are various properties and methods by QDateEdit are implemented in QDateTimeEdit. Below the relatable properties that can be used for this class.
- The date holds the date displayed by the widget.
- minimumDate − User can set the earliest date.
- maximumDate − User can set the new or current date.
- displayFormat − This method defines the string formats and it displays in the widget.
Example 1
We use the various methods of QDateEdit to display the date edits.
import sys
from PyQt6.QtWidgets import *
from PyQt6 import QtCore, QtGui
from PyQt6.QtGui import *
from PyQt6.QtCore import *
class Window(QMainWindow):
def __init__(self):
super().__init__()
# setting title
self.setWindowTitle("Date Edit(PyQt)")
# setting geometry
self.setGeometry(100, 100, 500, 400)
# calling method
self.UiComponents()
# showing all the widgets
self.show()
# method for components
def UiComponents(self):
# creating a QDateEdit widget
date = QDateEdit(self)
# setting geometry of the date edit
date.setGeometry(100, 100, 150, 40)
# creating a label
label = QLabel("Tutorialspoint", self)
# setting geometry
label.setGeometry(100, 150, 200, 60)
# making label multiline
label.setWordWrap(True)
# adding action to the date when enter key is pressed
date.editingFinished.connect(lambda: date_method())
# method called by date edit
def date_method():
# getting the date
value = date.date()
# setting text to the label
label.setText("Selected Date : " + str(value))
# create pyqt5 app
App = QApplication(sys.argv)
# create the instance of our Window
window = Window()
# start the app
sys.exit(App.exec())
Output
The above code produces the following output −
Example 2
Here, we will display the date edits using QDateEdit.
import sys
from PyQt6.QtWidgets import QApplication, QMainWindow, QDateEdit
from PyQt6.QtCore import QDate
app = QApplication(sys.argv)
wid = QMainWindow()
wid.setGeometry(400, 400, 250, 250)
wid.setWindowTitle("PyQt")
date = QDateEdit(wid)
date.setMinimumDate(QDate(1900, 1, 1))
date.setMaximumDate(QDate(2400, 12, 31))
date.move(50, 50)
wid.show()
sys.exit(app.exec())
Output
The above code produces the following output −