[Qgis-user] qt designer does not have/show QgsDateEdit widget

Janneke van Dijk janneke.qgis at gmail.com
Wed Jul 20 02:50:16 PDT 2022


Hi Richard and Andrea (and others),

thanks for clarifying/confirming - then it is not something I
misunderstood. I originally had the QDateEdit widget, which was working,
but giving a warning that it will not accept NULL values. As I would like
to be able to set it to NULL I thought of using QgsDateEdit. I have now
indeed managed to instead format the QgsDateTimeEdit widget to only show
the date, which will do for my purpose.

I am now trying to adjust the code that was working for QDateEdit to work
for the QgsDateTimeEdit with the following function that gets called
clicking a button. The first message will display the time and date
correctly, so 'now' seems to have the correct value. The second message
does not get displayed, but I also do not get an error message, and the
date does not get changed. Which makes me believe
"self.assesmentdate.setDateTime(now)" is not correct.

    def assesmentdate_now(self):
        if self and self.layer.isEditable():
            now = QtCore.QDateTime.currentDateTime()
            QgsMessageLog.logMessage(now.toString(), 'MyPlugin',
level=Qgis.Info)
            self.assesmentdate.setDateTime(now)
            QgsMessageLog.logMessage('test', 'MyPlugin', level=Qgis.Info)


What would be the correct syntax for setting the QgsDateTimeEdit widget to
show the current date?  Or does anyone have ideas how I can find out what's
happening, seeing that I am not getting error messages? The script gets
called by the attribute form.

Thanks for any thoughts,
Janneke

On Wed, Jul 20, 2022 at 10:44 AM Richard Duivenvoorde <rdmailings at duif.net>
wrote:

> Hi Janneke,
>
> I'm on master here with designer with all qgs widgets, and I do not have
> it either.
>
> When I create a form though, with a field which has a datetime field, I
> CAN set the 'Field Format' to 'Date'-only...
>
> So maybe there is some extra sip/development work needed to make this
> widget also available in QtDesigner?
> (try to ask this question on the defv list?)
>
> Or (not tested), maybe you can create an ui iwth QgsDateTime, and manually
> edit the ui file?
>
> HTH, Regards,
>
> Regards,
>
> Richard Duivenvoorde
>
> On 7/19/22 20:28, Janneke van Dijk via Qgis-user wrote:
> > Dear all,
> >
> > I need a date widget that can be set to a null date. From
> https://qgis.org/pyqgis/master/gui/QgsDateEdit.html#module-QgsDateEdit <
> https://qgis.org/pyqgis/master/gui/QgsDateEdit.html#module-QgsDateEdit> I
> understand that this should be possible (from 3.14 upwards). In Qt Designer
> (osgeo4W/bin/qgis-designer.bat which I understand is shipped with QGIS
> 3.26) I only see the QgsDateTimeEdit widget.
> >
> > image.png
> >
> > How can I use the QgsDateEdit widget?
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20220720/42be7bd7/attachment.htm>


More information about the Qgis-user mailing list