[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: Re: [PyQt] How to have QML interpret a property as null (instead of undefined)?
From: oliver <oliver.schoenborn () gmail ! com>
Date: 2017-10-12 16:27:49
Message-ID: CAMb+DaVkkQT7AMjpU-ZGEkyUXFK4TqkrFjTRqCAUvMWfA2jRTg () mail ! gmail ! com
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
Is this a documented technique? If not, I would avoid it. Use only the
documented way of doing this, and if none is documented, there is likely a
reason that the feature is not available. In that case, find and understand
the reason, and fix your design accordingly.
On Thu, 12 Oct 2017 at 11:25 Russell Warren <russ@perspexis.com> wrote:
> Solution found: Returning a freshly instantiated QObject() does the
> trick. QML interprets this as a null. ie:
>
> @pyqtProperty(QVariant, notify = publicPropertyChanged)#'QDateTime')
> def my_date(self):
> if self._my_date is None:
> return QObject() # QML interprets this as null
> return QDateTime(self._my_date) # no PyQt autoconvert for
> datetime->QVariant
> _______________________________________________
> PyQt mailing list PyQt@riverbankcomputing.com
> https://www.riverbankcomputing.com/mailman/listinfo/pyqt
--
Oliver
My StackOverflow contributions
My CodeProject articles
My Github projects
My SourceForget.net projects
[Attachment #5 (text/html)]
<div dir="ltr">Is this a documented technique? If not, I would avoid it. Use only the \
documented way of doing this, and if none is documented, there is likely a reason \
that the feature is not available. In that case, find and understand the reason, and \
fix your design accordingly.</div><br><div class="gmail_quote"><div dir="ltr">On Thu, \
12 Oct 2017 at 11:25 Russell Warren <<a \
href="mailto:russ@perspexis.com">russ@perspexis.com</a>> \
wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 \
.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Solution found: \
Returning a freshly instantiated QObject() does the trick. QML interprets this as a \
null. ie:<div><br></div><div></div></div><div dir="ltr"><div><div \
style="font-size:9.6px"><font face="monospace, monospace" \
color="#351c75">@pyqtProperty(QVariant, notify = \
publicPropertyChanged)#'QDateTime')</font></div><div \
style="font-size:9.6px"><font face="monospace, monospace" color="#351c75">def \
my_date(self):</font></div><div style="font-size:9.6px"><font face="monospace, \
monospace" color="#351c75"> if self._my_date is \
None:<br></font></div></div></div><div dir="ltr"><div><div \
style="font-size:9.6px"><font face="monospace, monospace" color="#351c75"> \
return QObject() # QML interprets this as null</font></div></div></div><div \
dir="ltr"><div><div style="font-size:9.6px"><font face="monospace, monospace" \
color="#351c75"> return QDateTime(self._my_date) # no PyQt autoconvert for \
datetime->QVariant</font></div></div></div> \
_______________________________________________<br> PyQt mailing list <a \
href="mailto:PyQt@riverbankcomputing.com" \
target="_blank">PyQt@riverbankcomputing.com</a><br> <a \
href="https://www.riverbankcomputing.com/mailman/listinfo/pyqt" rel="noreferrer" \
target="_blank">https://www.riverbankcomputing.com/mailman/listinfo/pyqt</a></blockquote></div><div \
dir="ltr">-- <br></div><div class="gmail_signature" \
data-smartmail="gmail_signature"><div dir="ltr">Oliver<div>My StackOverflow \
contributions<br><div>My CodeProject articles</div></div><div>My Github \
projects</div><div>My SourceForget.net projects</div></div></div>
[Attachment #6 (text/plain)]
_______________________________________________
PyQt mailing list PyQt@riverbankcomputing.com
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic