QDateEdit return to previous state on button click in Qt C++ -
i have qdateedit
in form in qt , want on button click qdateedit
returns previous state. how can done?
at moment state of qdateedit
(which specialized qdatetimeedit
) can retrieved calling date()
method.
then, said, need put value qdate
variable of class , create slot connect button click , calls setdate
set qdateedit
date.
below code snippet shows 1 way this.
#ifndef mydialog_h #define mydialog_h #include <qdialog> #include <qhboxlayout> #include <qdateedit> #include <qpushbutton> class dialog: public qdialog { q_object public: dialog(qwidget *parent = 0) : qdialog(parent), layout(this), edit(), button("reset",this) { layout.addwidget(&edit); layout.addwidget(&button); date = edit.date(); connect(&button, signal( clicked() ), this, slot( resettime() ) ); } public slots: void resettime() { edit.setdate(date); } private: qhboxlayout layout; qdateedit edit; qpushbutton button; qdate date; }; #endif
main.cc completeness
#include <qapplication> #include "dialog.h" int main(int argc, char** argv) { qapplication app(argc, argv); dialog dialog; dialog.show(); return app.exec(); }
let me know if helps.
Comments
Post a Comment