Class: QgsDateTimeEdit

The QgsDateTimeEdit class is a QDateTimeEdit with the capability of setting/reading null date/times.

Warning

You should use the signal valueChanged of this subclass rather than QDateTimeEdit.dateTimeChanged. (If you consequently connect parent’s dateTimeChanged signal and call dateTime() afterwards there is no guarantee that NULL values will be correctly handled).

See also

QgsDateEdit

See also

QgsTimeEdit

Class Hierarchy

Inheritance diagram of qgis.gui.QgsDateTimeEdit

Base classes

QDateTimeEdit

QAbstractSpinBox

QWidget

QObject

QPaintDevice

Subclasses

QgsDateEdit

The QgsDateEdit class is a QDateEdit widget with the capability of setting/reading null dates.

QgsTimeEdit

The QgsTimeEdit class is a QTimeEdit widget with the capability of setting/reading null date/times.

Methods

allowNull

If the widget allows setting null date/time.

clear

Set the current date as NULL.

date

Returns the date which can be a null date.

dateTime

Returns the date time which can be a null date/time.

displayNull

write the null value representation to the line edit without changing the value

emitValueChanged

Emits the widget's correct value changed signal.

event

Reimplemented to enable/disable the clear action depending on read-only status

isNull

Returns True if the widget is currently set to a null value

nullRepresentation

Returns the widget's NULL representation, which defaults to QgsApplication.nullRepresentation().

setAllowNull

Determines if the widget allows setting null date/time.

setDateTime

Set the date time in the widget and handles null date times.

setEmpty

Resets the widget to show no value (ie, an "unknown" state).

setNullRepresentation

Sets the widget's null representation, which defaults to QgsApplication.nullRepresentation().

time

Returns the time which can be a null time.

Signals

valueChanged

Signal emitted whenever the value changes.

class qgis.gui.QgsDateTimeEdit[source]

Bases: QDateTimeEdit

__init__(parent: QWidget | None = None)

Constructor for QgsDateTimeEdit. The current date and time is used by default. The widget is allowing null by default. If allow null is disabled, you should check allowNull before getting values from the widget.

Parameters:

parent (Optional[QWidget] = None)

allowNull(self) bool[source]

If the widget allows setting null date/time.

See also

setAllowNull()

Return type:

bool

clear(self)[source]

Set the current date as NULL.

Note

If the widget is not configured to accept NULL dates, this will have no effect.

date(self) QDate[source]

Returns the date which can be a null date.

Added in version 3.10.

Return type:

QDate

dateTime(self) QDateTime[source]

Returns the date time which can be a null date/time.

Note

Before QGIS 3.10, you mustn’t call date() or time() because they can’t return a NULL value.

Note

Since QDateTimeEdit.dateTime() is not virtual, dateTime must be called for QgsDateTimeEdit.

Return type:

QDateTime

displayNull(self, updateCalendar: bool = False)[source]

write the null value representation to the line edit without changing the value

Parameters:

updateCalendar (bool = False) – Flag if calendar is open and minimum date needs to be set

emitValueChanged(self, value: Any)[source]

Emits the widget’s correct value changed signal.

Parameters:

value (Any)

event(self, event: QEvent | None) bool[source]

Reimplemented to enable/disable the clear action depending on read-only status

Added in version 3.34.

Parameters:

event (Optional[QEvent])

Return type:

bool

isNull(self) bool[source]

Returns True if the widget is currently set to a null value

Return type:

bool

nullRepresentation(self) str[source]

Returns the widget’s NULL representation, which defaults to QgsApplication.nullRepresentation().

Added in version 3.14.

Return type:

str

setAllowNull(self, allowNull: bool)[source]

Determines if the widget allows setting null date/time.

See also

allowNull()

Parameters:

allowNull (bool)

setDateTime(self, dateTime: QDateTime | datetime.datetime)[source]

Set the date time in the widget and handles null date times.

Note

Since QDateTimeEdit.setDateTime() is not virtual, setDateTime must be called for QgsDateTimeEdit.

Parameters:

dateTime (Union[QDateTime, datetime.datetime])

setEmpty(self)[source]

Resets the widget to show no value (ie, an “unknown” state).

setNullRepresentation(self, null: str | None)[source]

Sets the widget’s null representation, which defaults to QgsApplication.nullRepresentation().

Added in version 3.14.

Parameters:

null (Optional[str])

time(self) QTime[source]

Returns the time which can be a null time.

Added in version 3.10.

Return type:

QTime

signal valueChanged(date: QDateTime)[source]

Signal emitted whenever the value changes.

Parameters:

date (QDateTime) – The new date/time value.