On Tue, Aug 2, 2011 at 10:45 AM, Stuart McGraw <[email protected]> wrote:
> Hello,
>
> Sorry for is probably really dumb, simple question,
> but I've just started with Pyside/Qt.  I'm rewriting
> a small wxPython app in Pyside and am stuck on this
> point.  (I am going through Summerfield's book and
> using the Pyside/Qt docs but have not seen an answer
> although I could easily have missed it.)
>
> My app gets data from a RDMS and thus many data items
> may be null rather than a domain value.
> For example a date field may be <2011-08-01> or null.
> I expected a null date (which is represented as a Python
> None within my program) could be used to set a QDate
> widget and would result in a blank field being shown
> but
>  my_date_widget.setDate (None)
> produces a TypeError.
>
> The Qt docs are not clear (to me) but I think say that
> a null QDate is the same as an invalid QDate so I tried
> the following
>  qdateNull = QtCore.QDate (0, 0, 0)  # An invalid QDate object.
>  # 'due' is a Python datetime.date object or None.
>  if not due:
>    self.due.setDate (qdateNull)
>  else:
>    self.due.setDate (Qdate (due.year, due.month, due.day))
> However, the "Due" field on the form shows "2000-01-01"
> when the value of 'due' is None.
>
> How the heck do I get a Qdate field to be blank when the
> corresponding date value is None?

You can use QDate(), which builds an invalid QDate().

Converting None to QDate() "under the hoods" could be implemented
kinda easily. What do you guys think?

-- 
Lauro Moura
INdT - Instituto Nokia de Tecnologia
_______________________________________________
PySide mailing list
[email protected]
http://lists.pyside.org/listinfo/pyside

Reply via email to