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

2022-03-25 Thread Richard Duivenvoorde via QGIS-Developer

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___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer


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

2022-03-25 Thread PIERRE Sylvain via QGIS-Developer
Hi Andeas,

Good tip !
I have to keep init script for good reason ;-). But I was not aware (not enough 
yet) of such possibilities. So for setting current date it’s pretty cool.
QGIS will still be amazing !

Thanks again

[cid:image009.jpg@01D8402E.DD9E9320]
Sylvain PIERRE
Chef de projet système d’information
Direction des Systèmes d’Information et du Développement Numérique
Service Projets et Ingénierie Numérique
Collectivité européenne d’Alsace
Tél : 03 88 76 68 88
sylvain.pie...@alsace.eu<mailto:sylvain.pie...@alsace.eu>
www.alsace.eu<http://www.alsace.eu>
[facebook]<http://www.facebook.com/toutelalsace> [twitter] 
<http://www.twitter.com/toutelalsace>  [insta] 
<http://www.instagram.com/toutelalsace>

De : Andreas Neumann 
Envoyé : vendredi 25 mars 2022 09:28
À : Denis Rouzaud 
Cc : PIERRE Sylvain ; qgis-developer@lists.osgeo.org
Objet : Re: [QGIS-Developer] Drag and drop form function QdateEdit Widget init

Soyez vigilant : ce courriel provient d'une organisation externe à la CeA.
• Assurez-vous d’abord qu’il ne s’agit pas d’un email malveillant avant de 
cliquer sur tout lien ou pièce jointe.
Apprendre à reconnaître un email de 
phishing.<https://intranet.alsace.eu/actualites/apprenez-a-reconnaitre-un-email-phishing/>

Hi Pierre,

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

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.

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.

Greetings,

Andreas

On 2022-03-25 09:17, Denis Rouzaud via QGIS-Developer wrote:
QgsDateTimeEdit implements setDateTime, which is not virtual in QDateTimeEdit.
It's probably that you have to find a QDateTimeEdit rather than the Qt native 
one.

Not 100% sure this is the issue though, but it won't hurt.

Le ven. 25 mars 2022 à 09:11, PIERRE Sylvain via QGIS-Developer 
mailto:qgis-developer@lists.osgeo.org>> a écrit 
:

Thanks for tip Richard, but I've tried with
today = QtCore.QDateTime.currentDateTime()
But it's not working




-Message d'origine-
De : Richard Duivenvoorde mailto:rdmaili...@duif.net>>
Envoyé : vendredi 25 mars 2022 08:50
À : PIERRE Sylvain mailto:sylvain.pie...@alsace.eu>>; 
qgis-developer@lists.osgeo.org<mailto:qgis-developer@lists.osgeo.org>
Objet : Re: [QGIS-Developer] Drag and drop form function QdateEdit Widget init

Soyez vigilant : ce courriel provient d'une organisation externe à la CeA.
• Assurez-vous d'abord qu'il ne s'agit pas d'un email malveillant avant de 
cliquer sur tout lien ou pièce jointe.
==

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
___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org<mailto:QGIS-Developer@lists.osgeo.org>
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer

___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org<mailto:QGIS-Developer@lists.osgeo.org>
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer


___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer


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

2022-03-25 Thread Andreas Neumann via QGIS-Developer

Hi Pierre,

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


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.


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.


Greetings,

Andreas

On 2022-03-25 09:17, Denis Rouzaud via QGIS-Developer wrote:

QgsDateTimeEdit implements setDateTime, which is not virtual in 
QDateTimeEdit.
It's probably that you have to find a QDateTimeEdit rather than the Qt 
native one.


Not 100% sure this is the issue though, but it won't hurt.

Le ven. 25 mars 2022 à 09:11, PIERRE Sylvain via QGIS-Developer 
 a écrit :



Thanks for tip Richard, but I've tried with
today = QtCore.QDateTime.currentDateTime()
But it's not working

-Message d'origine-
De : Richard Duivenvoorde 
Envoyé : vendredi 25 mars 2022 08:50
À : PIERRE Sylvain ; 
qgis-developer@lists.osgeo.org
Objet : Re: [QGIS-Developer] Drag and drop form function QdateEdit 
Widget init


Soyez vigilant : ce courriel provient d'une organisation externe à la 
CeA.
* Assurez-vous d'abord qu'il ne s'agit pas d'un email malveillant 
avant de cliquer sur tout lien ou pièce jointe.

==

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
___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer


___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer


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

2022-03-25 Thread Denis Rouzaud via QGIS-Developer
QgsDateTimeEdit implements setDateTime, which is not virtual in
QDateTimeEdit.
It's probably that you have to find a QDateTimeEdit rather than the Qt
native one.

Not 100% sure this is the issue though, but it won't hurt.

Le ven. 25 mars 2022 à 09:11, PIERRE Sylvain via QGIS-Developer <
qgis-developer@lists.osgeo.org> a écrit :

>
> Thanks for tip Richard, but I've tried with
> today = QtCore.QDateTime.currentDateTime()
> But it's not working
>
>
>
>
> -Message d'origine-
> De : Richard Duivenvoorde 
> Envoyé : vendredi 25 mars 2022 08:50
> À : PIERRE Sylvain ;
> qgis-developer@lists.osgeo.org
> Objet : Re: [QGIS-Developer] Drag and drop form function QdateEdit Widget
> init
>
> Soyez vigilant : ce courriel provient d'une organisation externe à la CeA.
> • Assurez-vous d’abord qu’il ne s’agit pas d’un email malveillant avant de
> cliquer sur tout lien ou pièce jointe.
> ==
>
> 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
> ___
> QGIS-Developer mailing list
> QGIS-Developer@lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
>
___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer


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

2022-03-25 Thread PIERRE Sylvain via QGIS-Developer

Thanks for tip Richard, but I've tried with 
today = QtCore.QDateTime.currentDateTime()
But it's not working


  

-Message d'origine-
De : Richard Duivenvoorde  
Envoyé : vendredi 25 mars 2022 08:50
À : PIERRE Sylvain ; qgis-developer@lists.osgeo.org
Objet : Re: [QGIS-Developer] Drag and drop form function QdateEdit Widget init

Soyez vigilant : ce courriel provient d'une organisation externe à la CeA.
• Assurez-vous d’abord qu’il ne s’agit pas d’un email malveillant avant de 
cliquer sur tout lien ou pièce jointe.
==

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
___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer


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

2022-03-25 Thread Richard Duivenvoorde via QGIS-Developer

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
___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer


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

2022-03-25 Thread PIERRE Sylvain via QGIS-Developer
Hi,
I build a form for a layer with drag and drop mode, and I use an init function 
to init some value for some widdget. I have no problem to do that with 
Qcombobox an QLineEdit widget :


linedit_imat = dialog.findChild(QLineEdit,"code_eqpt")
linedit_imat.setText(imatEqpt)

linedit_com = dialog.findChild(QLineEdit,"fk_commune")
linedit_com.setText(find_comtxt)

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

Thanks

[cid:image002.jpg@01D84022.F648C6E0]
Sylvain PIERRE
Chef de projet système d'information
Direction des Systèmes d'Information et du Développement Numérique
Service Projets et Ingénierie Numérique
Collectivité européenne d'Alsace
Tél : 03 88 76 68 88
sylvain.pie...@alsace.eu
www.alsace.eu
[facebook] [twitter] 
  [insta] 


___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer