0

I have extended QDateTimeEdit to do steps in intervals of 15 minutes by overwriting stepBy(int steps). So if a user scrolls up the minutes-section, the only choices they have are 0, 15, 30 and 45.

One problem appears if a user enters the dateTime manually, because then no validation takes place. I had a good look at: https://qt.gitorious.org/qt/qt/source/57756e72adf2081137b97f0e689dd16c770d10b1:src/gui/widgets/qdatetimeedit.cpp
but to be honest, the dateTimeFromText method was a bit overwhelming.

I also found: http://qt-project.org/doc/qt-5/qt.html#InputMethodHint-enum but still not sure if that is of any help.

Is there any easy way to only allow dateTimes that have a minutes-section of 0, 15, 30 or 45? Or can I alternatively disable manual input?

  • Did you forget about your last question? Why you can't use solution from my answer: http://stackoverflow.com/questions/26451420/restrict-qdatetimeedit-to-15-minutes/26452135#26452135 – Jablonski Oct 25 '14 at 08:54
  • Nope I did not. And no, I cannot. This is not enough validation. I'm learning qt and c++, hence I strife to achieve more and more ;) If I can't find a solution, I ask if someone else has faced the same problem. Apart from that, I upvoted your answer, still it's not enough for me. –  Oct 25 '14 at 09:26

1 Answers1

0

You can use dateTimeChanged slot to manually control if input is divisible by 15. Also you can update the element with one of the closest permitted values.

    if (dateTime.time().minute()%15 != 0) {
    QTime t(dateTime.time().hour(),dateTime.time().minute()-dateTime.time().minute()%15,dateTime.time().second());
    ui->dateTimeEdit->setTime(t);
}
ahaltindis
  • 338
  • 1
  • 6