0

Need to know UP/DOWN arrow button is clicked while implementing QDateTimeEdit in Qt?

I want to catch which button UP/DOWN clicked while changing the time. Please tell me the function which catches this signal.

Please reply me fast.

NG_
  • 6,895
  • 7
  • 45
  • 67

1 Answers1

1

That is quite simple.

To catch that you must create your own class inherited from QDateTimeEdit and reimplement stepBy(int steps) function.

So, your class will looks like:

class MyDateTime : public QDateTimeEdit
{
    Q_OBJECT
public:
    MyDateTime(QWidget *parent = 0);

public slots:
    void stepBy(int steps);
};

And implementation of void stepBy(int steps):

void MyDateTime::stepBy(int steps)
{
    // here you can do your own business
    if (steps!=0)
        qDebug( steps > 0
                ? "going up"
                : "going down" );
    // we must call it to provide QDateTimeEdit's
    // functionality
    QDateTimeEdit::stepBy(steps);
}

Good luck!

NG_
  • 6,895
  • 7
  • 45
  • 67
  • please let me kno how can i rollback min/sec from 59 to 00 or vice versa. Actually QDateTimeEdit doesnt allows it by default and it get stuck after reaching maximum value of 59 if tried pressing up arrow and same for minium value 00. – user1083212 Jan 08 '13 at 09:07
  • You got answer for your question. That is another question. – NG_ Jan 08 '13 at 09:47
  • Yes i got the answer for the first question. Now that was second query.. please help me in that. – user1083212 Jan 08 '13 at 09:59
  • One question per one thread. Please, mark this question as answered, and create new one, with your other question. – NG_ Jan 08 '13 at 10:14
  • Ok fine. switching to new thread. Follow this link http://stackoverflow.com/questions/14212762/in-qdatetimeedit-how-to-rollback-from-59-to-00-or-vice-versa-in-section-minute – user1083212 Jan 08 '13 at 10:17
  • You got answer, aren't you? Mark as answered. – NG_ Jan 08 '13 at 10:52
  • Thanx troyane, i am satisfied with your answer and i have accepted it. I will be thankfull agian if you answer my next query in new thread in last reply. – user1083212 Jan 08 '13 at 11:03