What shoud i do to create clicked() signal in my custom widget?
Printable View
What shoud i do to create clicked() signal in my custom widget?
You can have a boolean variable which will become true in mousePressEvent. In mouseReleaseEvent you can emit the signal clicked() if the boolean is true and then reset it again for the next click.
Hello.
Here is the sample code to do that..
.Code:
{ Q_OBJECT public: Button(....); protected: private: bool state; signals: void clicked(); void release(); void pressed(); }; Button::Button(............) { state = 0; } void Button::mousePressEvent(....) { state = 1; repaint(); emit pressed(); } void Button::mouseReleaseEvent(....) { state = 0; repaint(); emit released(); emit clicked(); } void Button::paintEvent(....) { if(state) ............... else .............; }
Based on the state value repaint the button as you need and call the signal with any object like this
Code:
Button *b = new Button(0); connect(b, SIGNAL(clicked()), qApp, SLOT(quit()));
You can try this options here
Cheers