Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: PyQT / QDate / QTableWidget

Reply
Thread Tools

Re: PyQT / QDate / QTableWidget

 
 
David Boddie
Guest
Posts: n/a
 
      03-28-2008
On Wed Mar 26 15:13:09 CET 2008, wrightee wrote:

> My server gives me a string y[0]: "20080327", which I convert to a
> QDateTime object using:
>
> x=QDateTime.fromString(y[0],"yyyymmdd")
>
> Printing x.toString("dd-mm-yyyy") gives me what I would expect -
> 27-03-2008


Strange. You should really be using "dd-MM-yyyy". Maybe this is why QDate
isn't behaving as you would expect - see below.

> What I'm trying to do though is add this to a QTableWidget item to
> create a date sortable column; I'm using this:
>
> if type(y)==QDateTime:
> item=QTableWidgetItem()
> item.setData(Qt.DisplayRole,QVariant(y))


This should work fine.

> BUT.. I'm adding 90 dates going back from today and getting values
> that look like this:
>
> 27/01/2007 00:12
> 28/01/2007 00:12
> 29/01/2007 00:12
> 30/01/2007 00:12
> 31/01/2007 00:12
> 01/01/2008 00:01
> 01/01/2008 00:02
> 01/01/2008 00:03
>
> etc


Right. You can see the date and time because you're using a QDateTime object.

> I tried using QDate but couldn't seem to be able to get
> QDate.fromString to create an object at all.


This may have something to do with the format string you tried.

> Could someone please advise where I'm going wrong, the end result
> should be a column in my QTableWidget formatted dd/mm/yyyy that can be
> sorted as dates, not strings, and originate from data formatted
> "YYYYMMDD"


Just use QDate objects instead of QDateTime objects and it should all just
work.

Good luck!

David
--
David Boddie
Lead Technical Writer, Trolltech ASA
 
Reply With Quote
 
 
 
 
wrightee
Guest
Posts: n/a
 
      03-31-2008
That worked! Thank you; I had given up on QDate but changing the
format worked perfectly.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
setTextAlignment function Qtablewidget PyQt Zabin Python 1 01-11-2010 01:07 AM
pyqt4 qTableWidget add items help ookrin Python 2 04-18-2009 06:16 PM
[PyQt4] QTableWidget non editable Antonio Valentino Python 1 06-22-2008 03:37 PM
Setting the value of one cell in QTableWidget fills everything. Constantly Distracted Python 3 03-29-2008 08:46 AM
PyQT / QDate / QTableWidget wrightee Python 0 03-26-2008 02:13 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57