c++ - Qt: Subclassed spinbox does not count -
i try subclass qt spinbox can mouse event. code compiles, events working, spinbox doesn't count or down. have set min value -9999 , max value 9999, default value 100. if click or down button, nothing happens.
newspinbox.h:
#ifndef newspinbox_h #define newspinbox_h #include <qobject> #include <qwidget> #include <qevent> #include <qmouseevent> #include <qspinbox> class newspinbox : public qspinbox { q_object public: newspinbox(qwidget *parent = 0); ~newspinbox(); public slots: void mousepressevent(qmouseevent *mouseevent); void mousereleaseevent(qmouseevent *mouseevent); }; #endif // newspinbox_h
newspinbox.cpp:
#include "newspinbox.h" newspinbox::newspinbox(qwidget *parent) : qspinbox(parent) { } newspinbox::~newspinbox() { } void newspinbox::mousepressevent(qmouseevent *mouseevent) { if(mouseevent->type() == qmouseevent::mousebuttonrelease) { int = 0; i++; } } void newspinbox::mousereleaseevent(qmouseevent *mouseevent) { if(mouseevent->type() == qmouseevent::mousebuttonrelease) { int = 0; i++; } }
do have reimplement count functions?
you must call base class handler default behavior:
void newspinbox::mousepressevent(qmouseevent *mouseevent) { qspinbox::mousepressevent(mouseevent); // ... code } void newspinbox::mousereleaseevent(qmouseevent *mouseevent) { qspinbox::mousereleaseevent(mouseevent); // ... code }
Comments
Post a Comment