-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbutton.cpp
More file actions
38 lines (31 loc) · 713 Bytes
/
button.cpp
File metadata and controls
38 lines (31 loc) · 713 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "button.h"
#include <QPainter>
#include <QGraphicsSceneMouseEvent>
Button::Button(const QString &text)
: m_width(100), m_height(62), text(text)
{
setAcceptHoverEvents(true);
}
void Button::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
{
painter->drawRect(boundingRect());
painter->drawText(boundingRect(), text);
}
void Button::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
event->accept();
}
void Button::mouseReleaseEvent(QGraphicsSceneMouseEvent *)
{
emit clicked();
}
void Button::resize(QSizeF size)
{
m_width = size.width();
m_height = size.height();
}
void Button::resize(qreal w, qreal h)
{
m_width = w;
m_height = h;
}