Hello.
Here is the sample code to do that..
{
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
.............;
}
class Button : public QWidget
{
Q_OBJECT
public:
Button(....);
protected:
void mousePressEvent(QMouseEvent*);
void mouseReleaseEvent(QMouseEvent*);
void paintEvent(QPaintEvent*);
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
.............;
}
To copy to clipboard, switch view to plain text mode
.
Based on the state value repaint the button as you need and call the signal with any object like this
Button *b = new Button(0);
connect(b, SIGNAL(clicked()), qApp, SLOT(quit()));
Button *b = new Button(0);
connect(b, SIGNAL(clicked()), qApp, SLOT(quit()));
To copy to clipboard, switch view to plain text mode
You can try this options here
Cheers
Bookmarks