Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-1138

QDateTimeEdit stepping behavior

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Out of scope
    • P3: Somewhat important
    • Some future release
    • 4.3.1
    • GUI: Look'n'Feel
    • None

    Description

      It would be nice with a separate mode for QDateTimeEdits that would make the stepping wrap differently.

      E.g.

      If you now step up from 31st of January on the day section it will go to the 1st of January

      In the other mode would go the 1st of February

      This can currently be achieved by subclassing like this:

      class DateTimeEdit : public QDateTimeEdit
      {
          Q_OBJECT
      public:
          DateTimeEdit(QWidget *parent = 0)
              : QDateTimeEdit(parent)
          {
              setWrapping(true);
          }
      
          void stepBy(int steps)
          {
              if (wrapping()) {
                  QDateTime currentTime = dateTime();
                  switch (currentSection()) {
                  case QDateTimeEdit::AmPmSection:
                      currentTime = currentTime.addSecs(((currentTime.time().hour() >= 12) ? -1 : 1) * 12*60*60)
                      break;
                  case QDateTimeEdit::MSecSection:
                      currentTime = currentTime.addMSecs(steps);
                      break;
                  case QDateTimeEdit::SecondSection:
                      currentTime = currentTime.addSecs(steps);
                      break;
                  case QDateTimeEdit::MinuteSection:
                      currentTime = currentTime.addSecs(steps*60);
                      break;
                  case QDateTimeEdit::HourSection:
                      currentTime = currentTime.addSecs(steps*60*60);
                      break;
                  case QDateTimeEdit::DaySection:
                      currentTime = currentTime.addDays(steps);
                      break;
                  case QDateTimeEdit::MonthSection:
                      currentTime = currentTime.addMonths(steps);
                      break;
                  case QDateTimeEdit::YearSection:
                      currentTime = currentTime.addYears(steps);
                      break;
                  default:
                      break;
                  }
                  QDateTimeEdit::setDateTime(currentTime);
              } else {
                  QDateTimeEdit::stepBy(steps);
              }
          }
      };
      

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              sorvig Morten Sørvig
              rve Anders Bakken
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes