Results 1 to 4 of 4

Thread: Date disappears in tableview

  1. #1
    Join Date
    Aug 2010
    Posts
    28
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Date disappears in tableview

    I have a item delegate to format my date in tableview. Here is this code

    class ticketDateFormatDelegate : public QStyledItemDelegate
    {
    public:
    ticketDateFormatDelegate (QString dateFormat, QObject *parent = 0) :
    QStyledItemDelegate(parent),
    m_dateFormat(dateFormat)
    {
    }
    virtual QString displayText(const QVariant & value, const QLocale & locale ) const
    { Q_UNUSED(locale);
    return value.toDate().toString(m_dateFormat);
    // return value.toDate().toString("MM/dd/yyyy");
    }
    private:
    QString m_dateFormat;
    };

    Here is the code that uses this

    ui->tableView->setItemDelegateForColumn(2,new ticketDateFormatDelegate("MM/dd/yy", this));

    Problem is when I tab off of the date, or I add a new line and default the date, it disappears from the view. The date is there because when I save the line the record is updated with whatever date is entered, just disappears in data entry. Any help?

  2. #2
    Join Date
    Jul 2010
    Posts
    41
    Thanks
    6
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Date disappears in tableview

    From Qt documentation (QVariant::toDate () const):
    If the type() is String, an invalid date will be returned if the string cannot be parsed as a Qt::ISODate format date.
    This means the 'value' must be in form Qt::ISODate!
    Do you check that 'value.toDate().isNull()' returns FALSE?
    For your remark: you should insert your code into code tag (button with sharp symbol)

  3. #3
    Join Date
    Aug 2010
    Posts
    28
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Date disappears in tableview

    I'm not sure I understand what you are saying. I default the value to a valid date. All I want to accomplish is that the date is formatted the way the customer wants to see it. Can you be a bit more specific.

  4. #4
    Join Date
    Jul 2010
    Posts
    41
    Thanks
    6
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Date disappears in tableview

    The Qt::ISODate format is YYYY-MM-DD for dates.
    If you default the value to a date like above then the code that you used:
    Qt Code:
    1. return value.toDate().toString(m_dateFormat);
    To copy to clipboard, switch view to plain text mode 
    is correct, but if you default it in another form you should use a code like this one:
    Qt Code:
    1. //myDateFormat is of type 'Qt::DateFormat' and is same as
    2. //the date format that you use for filling date cells.
    3. return QDate::fromString ( value.toString(), myDateFormat);
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Focus in QDockWidget disappears
    By Debilski in forum Qt Programming
    Replies: 3
    Last Post: 30th March 2011, 12:40
  2. Qt Creator sidebar disappears
    By szisziszilvi in forum Qt Tools
    Replies: 3
    Last Post: 9th January 2011, 19:23
  3. my window disappears quickly
    By Abeer in forum Newbie
    Replies: 2
    Last Post: 30th May 2010, 01:04
  4. Character from argument disappears
    By Pepe in forum Qt Programming
    Replies: 13
    Last Post: 19th June 2007, 23:48
  5. How to default Date-Edit Widget to system date
    By JohnToddSr in forum Qt Tools
    Replies: 4
    Last Post: 17th January 2007, 19:18

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.