qtqt5qdatetime

QTimeEdit, change only hours?


In my application I have a QTimeEdit, in which I only want to edit the hours. Is it possible to do that? (Disable editing of minutes)


Solution

  • You could override void QDateTimeEdit::stepBy(int steps) to add/remove hours only.

    Though the Qt code seems a bit complicated for that task : https://code.woboq.org/qt5/qtbase/src/widgets/widgets/qdatetimeedit.cpp.html#_ZN13QDateTimeEdit6stepByEi