Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to modify QDateTime format in QTableView of QFileSystemModel ?
Forum Updated to NodeBB v4.3 + New Features

How to modify QDateTime format in QTableView of QFileSystemModel ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 5 Posters 3.0k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sonichy
    wrote on 29 Dec 2017, 15:17 last edited by
    #1

    QTableView of QFileSystemModel:
    How to change QDateTime format to YYYY/MM/dd HH:mm:ss.
    How to change QTableView header ?
    https://github.com/sonichy/HTYFileManager

    alt text

    https://github.com/sonichy

    R 1 Reply Last reply 29 Dec 2017, 16:33
    0
    • S sonichy
      29 Dec 2017, 15:17

      QTableView of QFileSystemModel:
      How to change QDateTime format to YYYY/MM/dd HH:mm:ss.
      How to change QTableView header ?
      https://github.com/sonichy/HTYFileManager

      alt text

      R Offline
      R Offline
      Ratzz
      wrote on 29 Dec 2017, 16:33 last edited by
      #2

      @sonichy said in How to modify QDateTime format in QTableView of QFileSystemModel ?:

      How to change QDateTime format to YYYY/MM/dd HH:mm:ss.

      Have you tried
      QDateTime::fromString
      QDateTime::toString

      as shown here ?

      Header can be changed through setHorizontalHeaderLabels .

      --Alles ist gut.

      1 Reply Last reply
      1
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 29 Dec 2017, 20:54 last edited by
        #3

        Hi,

        A QStyledItemDelegate comes to mind for that or a QIdentityProxyModel.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        2
        • P Offline
          P Offline
          Pradeep Kumar
          wrote on 9 Jan 2018, 10:43 last edited by
          #4

          Hi,

          U can u yyyy/MM/dd HH:mm:ss
          year in small letters,
          toString() method is present for changing as desired.

          Thanks,

          Pradeep Kumar
          Qt,QML Developer

          1 Reply Last reply
          0
          • V Offline
            V Offline
            VRonin
            wrote on 9 Jan 2018, 11:21 last edited by VRonin 1 Sept 2018, 12:15
            #5

            I'm with Samuel here. Subclass QStyledItemDelegate.

            class DateFormatDelegate : public QStyledItemDelegate{
            Q_OBJECT
            Q_PROPERTY(QString dateFormat READ dateFormat WRITE setDateFormat NOTIFY dateFormatChanged)
            Q_DISABLE_COPY(DateFormatDelegate)
            public:
            explicit DateFormatDelegate(QObject *parent = Q_NULLPTR)
            :QStyledItemDelegate(parent),m_dateFormat("yyyy-MM-dd"){}
            DateFormatDelegate(const QString dtFormat,QObject *parent = Q_NULLPTR)
            :QStyledItemDelegate(parent),m_dateFormat(dtFormat){}
            QString displayText(const QVariant &value, const QLocale &locale) const Q_DECL_OVERRIDE{
            switch(value.type()){
            case QMetaType::QDate:
            return locale.toString(value.toDate(),m_dateFormat);
            case QMetaType::QDateTime:
            return locale.toString(value.toDateTime(),m_dateFormat);
            case QMetaType::QTime:
            return locale.toString(value.toTime(),m_dateFormat);
            default:
            return QStyledItemDelegate::displayText(value,locale);
            }
            }
            const QString& dateFormat() const {return m_dateFormat;}
            void setDateFormat(const QString& dtFormat){
            if(m_dateFormat==dtFormat) return;
            m_dateFormat=dtFormat;
            dateFormatChanged(m_dateFormat);
            }
            Q_SIGNAL void dateFormatChanged(const QString& dtFormat);
            private:
            QString m_dateFormat;
            };

            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
            ~Napoleon Bonaparte

            On a crusade to banish setIndexWidget() from the holy land of Qt

            1 Reply Last reply
            3

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved