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

StackOverflow https://stackoverflow.com/questions/14210081

  •  14-01-2022
  •  | 
  •  

문제

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.

도움이 되었습니까?

해결책

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!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top