Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. PySide6 QDateTimeEdit.setDateTime() doesn't respect timeSpec() - is it a bug or change from PySide2?

PySide6 QDateTimeEdit.setDateTime() doesn't respect timeSpec() - is it a bug or change from PySide2?

Scheduled Pinned Locked Moved Solved Qt for Python
6 Posts 2 Posters 775 Views
  • 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
    StarterKit
    wrote on last edited by
    #1

    Hi,
    below you may find an example of code. It takes Unix timestamp value 1633315080 that represents 2021-10-04 02:38:00 GMT (you may check it at https://www.epochconverter.com/). Then it converts this value into QDateTime object and displays it in QDateTimeEdit widget.
    From print output in console I have:
    Date/Time: 2021-10-04 02:38:00
    Spec: PySide6.QtCore.Qt.TimeSpec.UTC
    that is right, but in GUI window I see 03/10/2021 23:38:00 that is not right.
    If I replace PySide6 by PySide2 I have the same output in console but 2021-10-04 02:38:00 is displayed in GUI.

    I.e. it means for both PySide2/PySide6 I have correct timeSpec (UTC) set for QDateTimeEdit. But when setDateTime() is called PySide2 takes its argument as UTC time (that matches timeSpec) but PySide6 takes its argument as local time (and then, for me, shifts it by 3 hours to UTC).

    But I haven't seen anything about it in Qt5->Qt6 porting quide. So, was there a behavior change of QDateTimeEdit.setDateTime() method or it is a bug? May someone comment?

    Here is the code:

    from datetime import datetime
    from PySide6.QtCore import Qt
    from PySide6.QtWidgets import QApplication, QMainWindow, QDateTimeEdit
    
    app = QApplication([])
    window = QMainWindow()
    
    editor = QDateTimeEdit(window)
    editor.setTimeSpec(Qt.UTC)
    editor.setFixedWidth(editor.fontMetrics().horizontalAdvance("00/00/0000 00:00:00") * 1.25)
    editor.setDisplayFormat("dd/MM/yyyy hh:mm:ss")
    
    timestamp = 1633315080  # 2021-10-04 02:38:00 GMT
    date_time = datetime.utcfromtimestamp(timestamp)
    print(f"Date/Time: {date_time}")
    
    editor.setDateTime(date_time)
    print(f"Spec: {editor.timeSpec()}")
    window.show()
    app.exec()
    
    S 1 Reply Last reply
    0
    • S StarterKit

      Hi,
      below you may find an example of code. It takes Unix timestamp value 1633315080 that represents 2021-10-04 02:38:00 GMT (you may check it at https://www.epochconverter.com/). Then it converts this value into QDateTime object and displays it in QDateTimeEdit widget.
      From print output in console I have:
      Date/Time: 2021-10-04 02:38:00
      Spec: PySide6.QtCore.Qt.TimeSpec.UTC
      that is right, but in GUI window I see 03/10/2021 23:38:00 that is not right.
      If I replace PySide6 by PySide2 I have the same output in console but 2021-10-04 02:38:00 is displayed in GUI.

      I.e. it means for both PySide2/PySide6 I have correct timeSpec (UTC) set for QDateTimeEdit. But when setDateTime() is called PySide2 takes its argument as UTC time (that matches timeSpec) but PySide6 takes its argument as local time (and then, for me, shifts it by 3 hours to UTC).

      But I haven't seen anything about it in Qt5->Qt6 porting quide. So, was there a behavior change of QDateTimeEdit.setDateTime() method or it is a bug? May someone comment?

      Here is the code:

      from datetime import datetime
      from PySide6.QtCore import Qt
      from PySide6.QtWidgets import QApplication, QMainWindow, QDateTimeEdit
      
      app = QApplication([])
      window = QMainWindow()
      
      editor = QDateTimeEdit(window)
      editor.setTimeSpec(Qt.UTC)
      editor.setFixedWidth(editor.fontMetrics().horizontalAdvance("00/00/0000 00:00:00") * 1.25)
      editor.setDisplayFormat("dd/MM/yyyy hh:mm:ss")
      
      timestamp = 1633315080  # 2021-10-04 02:38:00 GMT
      date_time = datetime.utcfromtimestamp(timestamp)
      print(f"Date/Time: {date_time}")
      
      editor.setDateTime(date_time)
      print(f"Spec: {editor.timeSpec()}")
      window.show()
      app.exec()
      
      S Offline
      S Offline
      StarterKit
      wrote on last edited by StarterKit
      #2

      Ok, in web-manual of QDateTimeEdit.dateTime property I see:
      for Qt6:
      When setting this property, the new QDateTime is converted to the timespec of the QDateTimeEdit, which thus remains unchanged.
      for Qt5:
      When setting this property the timespec of the QDateTimeEdit remains the same and the timespec of the new QDateTime is ignored.

      So, indeed, behavior was changed...
      But... Is there anywhere a list of such changes? It's a bit annoying to find them occasionally one by one...

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        There's the list of changes. If that one is not on there, I would say that this is a documentation bug.

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

        S 1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

          There's the list of changes. If that one is not on there, I would say that this is a documentation bug.

          S Offline
          S Offline
          StarterKit
          wrote on last edited by
          #4

          @SGaist, QDateTimeEdit is from Qt Widgets so I assume this change should be described on this page but I don't see it there. I.e. it appears the list of changes is incomplete :(

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            You should open a bug report for the documentation about that behaviour change.

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

            S 1 Reply Last reply
            0
            • SGaistS SGaist

              You should open a bug report for the documentation about that behaviour change.

              S Offline
              S Offline
              StarterKit
              wrote on last edited by
              #6

              @SGaist https://bugreports.qt.io/browse/QTBUG-97493

              1 Reply Last reply
              2

              • Login

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