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. Time format in QTableView with QSqlTableModel
Qt 6.11 is out! See what's new in the release blog

Time format in QTableView with QSqlTableModel

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 6.5k Views 1 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.
  • J Offline
    J Offline
    jarda
    wrote on last edited by
    #1

    Hello all,

    I have QSqlTableModel connected to MySQL table where one column has type 'time'.
    This column is used to store amount of time and I need to show it in hh:mm:ss format.
    But in connected QTableView it is shown as 12:10 AM instead of 00:10:00.

    Is there any way how to change the time format for this?

    Thanks in advance,

    Jaroslav

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      I think changing your locale to a locale that uses that format by default (at least for that QTableView widget) would do it.

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jarda
        wrote on last edited by
        #3

        Thank You Andre for help. Locale change helped (slightly). Now it is displayed as 'h:mm'. But I need also seconds - format 'hh:mm:ss'.

        Do you know how to do it?

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          Other than that, I think your best bet is to subclass [[doc:QStyledItemDelegate]] and reimplement the displayText() method. You just return the time in the format you like from there.

          1 Reply Last reply
          0
          • S Offline
            S Offline
            syrianzoro
            wrote on last edited by
            #5

            @QString QTime::toString ( const QString & format ) const@

            Format Result
            hh:mm:ss.zzz 14:13:09.042
            h:m:s ap 2:13:9 pm
            H:m:s a 14:13:9 pm

            Qt is the future

            1 Reply Last reply
            0

            • Login

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