2011/8/2 Stuart McGraw <[email protected]>: > On 08/02/2011 08:45 AM, Lauro Moura wrote: >> 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? > > Thanks for that info. It seems the problem is > not so much with QDate but with QDateEdit, since > the following script still shows "2000-01-01" in > the QDateEdit widget: > > import sys, datetime > from PyQt4.QtCore import * > from PyQt4.QtGui import * > > class Form (QDialog): > def __init__ (self, parent=None): > super (Form, self).__init__ (parent) > de = QDateEdit() > de.setDate (QDate()) > lo = QVBoxLayout() > lo.addWidget (de) > self.setLayout (lo) > > if __name__ == '__main__': > app = QApplication (sys.argv) > frame = Form() > frame.show() > app.exec_() > > Someone pointed me to > https://bugreports.qt.nokia.com//browse/QTBUG-277 > > Sadly, this is a show-stopper for me.
Actually isn't possible to set a null value to QDateEdit. A workaround may be a custom widget with a QLineEdit and a popup calendar, something like that http://darcs.pypapi.org/cgi-bin/darcsweb.cgi/darcsweb.cgi?r=pypapi;a=headblob;f=/lib/pypapi/ui/widgets/nullabledateedit.py Other better solutions? Tiziano _______________________________________________ PySide mailing list [email protected] http://lists.pyside.org/listinfo/pyside
