How to implement a widget for durations similar to QTimeEdit?



  • Hello,

    I want to let the user enter a duration in the format hh:mm:ss, but with the twist, that hh can be greater than 23. QTimeEdit cannot be modified this way, if I am not mistaken. I tried void setMaximumTime ( const QTime & max ), but of course a QTime only accepts hours up to 23, too. It seems, that I would have to implement my own widget. How would I go about this?

    Should I modify a QLineEdit with validation for the time format I want or is there a better way?



  • How about to use "input mask":http://qt-project.org/doc/qt-4.8/qlineedit.html#inputMask-prop on QLineEdit?



  • You are right, the standard time edit widget is worthless for this task.
    Indeed, I think you will have to implement your own formatting. Quite a while ago, I wrote a class that was meant to be included in Qt, but it never got integrated: QTimeSpan. It might be of help to you. It describes the concept of a duration or period of time, and it also provides formatting and parsing for these.

    Note that you are probably better off writing your own date and time widgets anyway. The default Qt ones are rather limited and don't play very nice when editing. I ended up writing our own date widget based on a line edit and a flexible date parser myself too.

    "QTimeSpan":http://gitorious.org/qtimespandevel


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.