[PyQt] How to clear QDateTime

Marc Nations mnations.lists at gmail.com
Mon Feb 2 22:00:55 GMT 2009


Thanks! ...it does work and functions like I need it to.
Marc

On Sun, Feb 1, 2009 at 3:24 PM, David Boddie <david at boddie.org.uk> wrote:

> On Sun Feb 1 20:53:45 GMT 2009, David Douard wrote:
> > Le Saturday 31 January 2009 19:15:23 Marc Nations, vous avez écrit :
>
> > > I can't seem to clear out the QDateTime field in cases where I don't
> want
> > > the date displayed. Using clear() seems to wipe out the first entry (in
> > > this case the hour). I tried hitting multiple clears thinking that it
> may
> > > just work down the list, but that didn't work. Is there a way to blank
> > > out the field completely? I know it can be disbled, but I'd like to
> have
> > > it be blank until the user goes and selects the pop-up calendar.
> >
> > This is a gap in Qt, and it won't happen before a while. See
> >
> http://www.qtsoftware.com/developer/task-tracker/index_html?method=entry&id
> >=135683
>
> One way to do this is to access the QLineEdit child widget of the
> QDateTimeEdit and clear that instead, like this:
>
>  dateTimeEdit = QDateTimeEdit()
>  lineEdit = dateTimeEdit.findChild(QLineEdit)
>  lineEdit.setText("")
>
> Note that this puts the QDateTimeEdit into a state where validation is not
> used, so you need to make sure that it's enabled again before you let the
> user enter text. Perhaps disable the QDateTimeEdit as well to prevent that
> from happening and set the current section when you enable it again.
>
> As with all these hacks to get at the widgets behind the scenes, it's not
> guaranteed to work, either now or in the future, but it may prove to be a
> useful workaround if it happens to work for you.
>
> David
>
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20090202/8d6bc71f/attachment.html


More information about the PyQt mailing list