[QGIS-Developer] Drag and drop form function QdateEdit Widget init

Richard Duivenvoorde rdmailings at duif.net
Fri Mar 25 00:49:50 PDT 2022


On 3/25/22 08:33, PIERRE Sylvain via QGIS-Developer wrote:

> But this is not working with QDateEdit widget :
> 
> today=date.today()
> 
> control=dialog.findChild(QDateEdit,"date_insert")
> 
> control.setDateTime(today)
> 
> What is the right syntax to init the date widget ? It’s impossible to debug init script (or may be I’m missing something…)

Hi,

Which module is 'date.today()' from, not Qt is it?

You probably have to use the QDatetime: https://doc.qt.io/qt-5/qdatetime.html#currentDateTime

>>> QDateTime.currentDateTime()
PyQt5.QtCore.QDateTime(2022, 3, 25, 8, 44, 19, 963)

And set THAT with the widget?

See: https://doc.qt.io/qt-5/qdatetimeedit.html#dateTime-prop

(it always a little hassle to juggle with date/time etc in Python/Qt)

Regards,

Richard Duivenvoorde


More information about the QGIS-Developer mailing list