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

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

  •  14-01-2022
  •  | 
  •  

Question

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.

Était-ce utile?

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

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top