Search code examples
qtqdatetime

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


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.


Solution

  • 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!