Results 1 to 4 of 4

Thread: QTableView & QDate

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2007
    Posts
    9
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QTableView & QDate

    Hi,
    I have a DB table with a date column on it, it has a short date format (dd/MM/yyyy). I use a QSqlTableModel to hold this table's data, and its connected to a QTableView. The problem is that when i display it, the data has a QDateTime format (dd/MM/yyyy 0:00:00). Although the date format is correct, i dont want the time to be displayed (its not recorded in the DB). I guess this is because a conversion between QVariant and the QString in the model...

    Any idea?

    Thx!

  2. #2
    Join Date
    Mar 2006
    Location
    The Netherlands
    Posts
    300
    Thanks
    9
    Thanked 29 Times in 29 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QTableView & QDate

    Reimplement the data() function of the model. If you want the table-view to display a date editor / date display, make sure you return a QDate.

    If you really want only a string there, you simply have to extract a QDate from the QVariant and use the correct format in the function QDate::toString().
    "The strength of a civilization is not measured by its ability to wage wars, but rather by its ability to prevent them." - Gene Roddenberry

  3. #3
    Join Date
    Jul 2007
    Posts
    9
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableView & QDate

    if i reimplement QSqlTableModel:ata() i will also have to take the updates of the table into account, is that correct? the table is editable, so this can be a bit difficult...
    Is there any other easier way?

    J.

  4. #4
    Join Date
    Mar 2006
    Location
    The Netherlands
    Posts
    300
    Thanks
    9
    Thanked 29 Times in 29 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QTableView & QDate

    For handling edits and updates on the table, reimplement setData(). That's how the model/view classes were designed to work together.
    "The strength of a civilization is not measured by its ability to wage wars, but rather by its ability to prevent them." - Gene Roddenberry

  5. The following user says thank you to Michiel for this useful post:

    Shaitan (19th July 2007)

Similar Threads

  1. QTableView sorting
    By gabriels in forum Qt Programming
    Replies: 11
    Last Post: 6th October 2010, 17:13
  2. QTableView currentChanged <> selecting header
    By Everall in forum Qt Programming
    Replies: 4
    Last Post: 1st April 2009, 08:24
  3. QTableView paints too much
    By Jimmy2775 in forum Qt Programming
    Replies: 2
    Last Post: 26th July 2006, 18:42
  4. Multi-line messages in QTableView
    By Conel in forum Qt Programming
    Replies: 6
    Last Post: 13th April 2006, 13:49
  5. Two QDate issues
    By GreyGeek in forum Qt Programming
    Replies: 2
    Last Post: 8th March 2006, 02:09

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.