[QGIS-Developer] Drag and drop form function QdateEdit Widget init
Richard Duivenvoorde
rdmailings at duif.net
Fri Mar 25 02:01:40 PDT 2022
On 3/25/22 09:04, PIERRE Sylvain wrote:
>
> Thanks for tip Richard, but I've tried with
> today = QtCore.QDateTime.currentDateTime()
> But it's not working
I get it working with:
from qgis.PyQt.QtWidgets import QWidget, QMessageBox, QDateEdit, QDateTimeEdit
from qgis.PyQt.QtCore import QDate, QDateTime
def my_form_open(dialog, layer, feature):
geom = feature.geometry()
control = dialog.findChild(QDateTimeEdit, "date")
# just to check that you actually DO find the control!
QMessageBox.warning(None, 'bla', f'control: "{control}"', QMessageBox.Ok, QMessageBox.Ok)
now = QDateTime.currentDateTime()
control.setDateTime(now)
Note that:
- I defined a field as Date-type
- the form apparently adds a QDateTimeEdit
- you set a QDateTime IN it
- but it shows me a date
HTH, regards,
Richard Duivenvoorde
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screenshot-20220325100059-345x243.png
Type: image/png
Size: 25792 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20220325/f2116879/attachment-0001.png>
More information about the QGIS-Developer
mailing list