Class: QgsDateTimeEdit

class qgis.gui.QgsDateTimeEdit(parent: QWidget = None)

Bases: PyQt5.QtWidgets.QDateTimeEdit

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.

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

Parameters

parent

actionEvent()
allowNull(self) → bool

If the widget allows setting null date/time.

See also

setAllowNull()

Return type

bool

changeEvent()
childEvent()
clear(self)

Set the current date as NULL.

Note

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

closeEvent()
connectNotify()
contextMenuEvent()
create()
customEvent()
date(self) → QDate

Returns the date which can be a null date.

New in version 3.10.

Return type

QDate

dateTime(self) → QDateTime

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

dateTimeFromText()
destroy()
disconnectNotify()
displayNull(self, updateCalendar: bool = False)

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

dragEnterEvent()
dragLeaveEvent()
dragMoveEvent()
dropEvent()
emitValueChanged(self, value: Any)

Emits the widget’s correct value changed signal.

Parameters

value (Any) –

enterEvent()
fixup()
focusInEvent(self, event: QFocusEvent)
Parameters

event (QFocusEvent) –

focusNextChild()
focusNextPrevChild()
focusOutEvent(self, event: QFocusEvent)
Parameters

event (QFocusEvent) –

focusPreviousChild()
hideEvent()
initPainter()
initStyleOption()
inputMethodEvent()
isNull(self) → bool

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

Return type

bool

isSignalConnected()
keyPressEvent()
keyReleaseEvent()
leaveEvent()
lineEdit()
metric()
mouseDoubleClickEvent()
mouseMoveEvent()
mousePressEvent(self, event: QMouseEvent)
Parameters

event (QMouseEvent) –

mouseReleaseEvent()
moveEvent()
nativeEvent()
nullRepresentation(self) → str

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

New in version 3.14.

Return type

str

paintEvent()
receivers()
resizeEvent()
sender()
senderSignalIndex()
setAllowNull(self, allowNull: bool)

Determines if the widget allows setting null date/time.

See also

allowNull()

Parameters

allowNull (bool) –

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

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

setEmpty(self)

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

New in version 2.16.

setLineEdit()
setNullRepresentation(self, null: str)

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

New in version 3.14.

Parameters

null (str) –

sharedPainter()
showEvent(self, event: QShowEvent)
Parameters

event (QShowEvent) –

stepEnabled()
tabletEvent()
textFromDateTime()
time(self) → QTime

Returns the time which can be a null time.

New in version 3.10.

Return type

QTime

timerEvent()
updateMicroFocus()
validate()
valueChanged

Signal emitted whenever the value changes.

Parameters

date (Union[QDateTime) – The new date/time value. [signal]

wheelEvent(self, event: QWheelEvent)
Parameters

event (QWheelEvent) –