10

By liuyanghejerry

No Comments

Categories: Qt Widget

Tags: , ,

AutoAdvance in QTimeEdit

AutoAdvance, is a feature that allows you step up or down in whole sections. For example, when 4:59 and you try to step up, you will get 5:00, when the feature is enabled.

This is a useful feature but disappeared since Qt 3.3. And below, is my own method to implement it.


class myTime : public QTimeEdit
{
Q_OBJECT
public:
virtual void stepBy(int steps)
{
if (this->time().minute()==59 && steps>0){
setTime(QTime(time().hour()+1,0,time().second(),time().msec()));
}else if(this->time().minute()==00 && steps<0){
setTime(QTime(time().hour()-1,59,time().second(),time().msec()));
}else{
QTimeEdit::stepBy(steps);
}
}
};

Keep in mind, to enable the code beyond, must setWrapping(true).

Comment Feed

No Responses (yet)



Some HTML is OK

or, reply to this post via trackback.