<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head><body style='font-size: 10pt; font-family: Verdana,Geneva,sans-serif'>
<p>Hi Pierre,</p>
<p>Not sure if you are aware that recent QGIS releases also have very good "default" value support without having to use Python. You can simply set default values with QGIS expressions. No need for Python code (unless you do something really special).</p>
<p>You can even set date values dependent on other widgets without having to use Python scripting - and do updates whenever something changes on the record, without having to fall back to Python scripting.</p>
<p>Just wanted to make sure you are aware of this alternative mechanism. There might still be good reasons for using Python scripting though - but theses cases are now rarer.</p>
<p>Greetings,</p>
<p>Andreas</p>
<p id="reply-intro">On 2022-03-25 09:17, Denis Rouzaud via QGIS-Developer wrote:</p>
<blockquote type="cite" style="padding: 0 0.4em; border-left: #1010ff 2px solid; margin: 0">
<div id="replybody1">
<div>
<div dir="ltr">QgsDateTimeEdit implements setDateTime, which is not virtual in QDateTimeEdit.
<div>It's probably that you have to find a QDateTimeEdit rather than the Qt native one.</div>
<div> </div>
<div>Not 100% sure this is the issue though, but it won't hurt.</div>
</div>
<br />
<div class="v1gmail_quote">
<div class="v1gmail_attr" dir="ltr">Le ven. 25 mars 2022 à 09:11, PIERRE Sylvain via QGIS-Developer <<a href="mailto:qgis-developer@lists.osgeo.org" rel="noreferrer">qgis-developer@lists.osgeo.org</a>> a écrit :</div>
<blockquote class="v1gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid #cccccc; padding-left: 1ex;"><br />Thanks for tip Richard, but I've tried with <br />            today = QtCore.QDateTime.currentDateTime()<br />But it's not working<br /><br /><br /><br /><br />-----Message d'origine-----<br />De : Richard Duivenvoorde <<a href="mailto:rdmailings@duif.net" rel="noreferrer">rdmailings@duif.net</a>> <br />Envoyé : vendredi 25 mars 2022 08:50<br />À : PIERRE Sylvain <<a href="mailto:sylvain.pierre@alsace.eu" rel="noreferrer">sylvain.pierre@alsace.eu</a>>; <a href="mailto:qgis-developer@lists.osgeo.org" rel="noreferrer">qgis-developer@lists.osgeo.org</a><br />Objet : Re: [QGIS-Developer] Drag and drop form function QdateEdit Widget init<br /><br />Soyez vigilant : ce courriel provient d'une organisation externe à la CeA.<br />• Assurez-vous d'abord qu'il ne s'agit pas d'un email malveillant avant de cliquer sur tout lien ou pièce jointe.<br />==================================================<br /><br />On 3/25/22 08:33, PIERRE Sylvain via QGIS-Developer wrote:<br /><br />> But this is not working with QDateEdit widget :<br />> <br />> today=date.today()<br />> <br />> control=dialog.findChild(QDateEdit,"date_insert")<br />> <br />> control.setDateTime(today)<br />> <br />> What is the right syntax to init the date widget ? It's impossible to debug init script (or may be I'm missing something...)<br /><br />Hi,<br /><br />Which module is 'date.today()' from, not Qt is it?<br /><br />You probably have to use the QDatetime: <a href="https://doc.qt.io/qt-5/qdatetime.html#currentDateTime" target="_blank" rel="noopener noreferrer">https://doc.qt.io/qt-5/qdatetime.html#currentDateTime</a><br /><br />>>> QDateTime.currentDateTime()<br />PyQt5.QtCore.QDateTime(2022, 3, 25, 8, 44, 19, 963)<br /><br />And set THAT with the widget?<br /><br />See: <a href="https://doc.qt.io/qt-5/qdatetimeedit.html#dateTime-prop" target="_blank" rel="noopener noreferrer">https://doc.qt.io/qt-5/qdatetimeedit.html#dateTime-prop</a><br /><br />(it always a little hassle to juggle with date/time etc in Python/Qt)<br /><br />Regards,<br /><br />Richard Duivenvoorde<br />_______________________________________________<br />QGIS-Developer mailing list<br /><a href="mailto:QGIS-Developer@lists.osgeo.org" rel="noreferrer">QGIS-Developer@lists.osgeo.org</a><br />List info: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" target="_blank" rel="noopener noreferrer">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br />Unsubscribe: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" target="_blank" rel="noopener noreferrer">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a></blockquote>
</div>
</div>
</div>
<br />
<div class="pre" style="margin: 0; padding: 0; font-family: monospace">_______________________________________________<br />QGIS-Developer mailing list<br /><a href="mailto:QGIS-Developer@lists.osgeo.org">QGIS-Developer@lists.osgeo.org</a><br />List info: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" target="_blank" rel="noopener noreferrer">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br />Unsubscribe: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" target="_blank" rel="noopener noreferrer">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a></div>
</blockquote>
<p><br /></p>

</body></html>