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. QTimeEdit in the QTableView problem

QTimeEdit in the QTableView problem

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 401 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.
  • M Offline
    M Offline
    Milosz
    wrote on last edited by Milosz
    #1

    Hi,
    I have a problem with displaying time in the QTableView.
    I want to display time in "mm:ss" format so I defined createEditor method in my delegate like that

    QWidget *MyDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
    {
        QTimeEdit *timeEdit = new QTimeEdit(parent);
        timeEdit->setDisplayFormat("mm:ss");
        timeEdit->setAlignment(Qt::AlignCenter);
        return timeEdit;
    }
    

    When I set a cell value say QTime(0,0,10) I see "00:00" in that cell,
    after doubleclick "00:10" and when I defocused this cell I can see 00:00 again.
    I checked data saving to model and they had proper value "00:00".

    Any suggestion?
    Thanks in advance

    JonBJ 1 Reply Last reply
    0
    • M Milosz

      Hi,
      I have a problem with displaying time in the QTableView.
      I want to display time in "mm:ss" format so I defined createEditor method in my delegate like that

      QWidget *MyDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
      {
          QTimeEdit *timeEdit = new QTimeEdit(parent);
          timeEdit->setDisplayFormat("mm:ss");
          timeEdit->setAlignment(Qt::AlignCenter);
          return timeEdit;
      }
      

      When I set a cell value say QTime(0,0,10) I see "00:00" in that cell,
      after doubleclick "00:10" and when I defocused this cell I can see 00:00 again.
      I checked data saving to model and they had proper value "00:00".

      Any suggestion?
      Thanks in advance

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @Milosz
      Hi. I have to say I am confused by your description. Maybe somebody else will understand better.

      Can we start with one thing: are you aware that createEditor() is only called while a cell is being edited (e.g. double-click)? The rest of the time is just a non-widget delegate displaying the text of a time.

      The display of values, whether for edit or not, does not affect what value is in the model. setEditorData() and setModelData() transfer values between model and editor.

      I do not know what issue you are reporting where.

      M 1 Reply Last reply
      0
      • JonBJ JonB

        @Milosz
        Hi. I have to say I am confused by your description. Maybe somebody else will understand better.

        Can we start with one thing: are you aware that createEditor() is only called while a cell is being edited (e.g. double-click)? The rest of the time is just a non-widget delegate displaying the text of a time.

        The display of values, whether for edit or not, does not affect what value is in the model. setEditorData() and setModelData() transfer values between model and editor.

        I do not know what issue you are reporting where.

        M Offline
        M Offline
        Milosz
        wrote on last edited by
        #3

        @JonB
        Thanks for the clarification.
        I think you understood very good the problem.

        You pointed: " The rest of the time is just a non-widget delegate displaying the text of a time"
        but I still have no idea how to magage the problem

        SGaistS 1 Reply Last reply
        1
        • M Milosz

          @JonB
          Thanks for the clarification.
          I think you understood very good the problem.

          You pointed: " The rest of the time is just a non-widget delegate displaying the text of a time"
          but I still have no idea how to magage the problem

          SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          Implement the displayText method of your delegate to return what you want to show.

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

          M 1 Reply Last reply
          3
          • SGaistS SGaist

            Hi,

            Implement the displayText method of your delegate to return what you want to show.

            M Offline
            M Offline
            Milosz
            wrote on last edited by
            #5

            @SGaist

            it works
            thanks a lot

            Miłosz

            1 Reply Last reply
            0
            • M Milosz has marked this topic as solved on

            • Login

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