-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbutton.cpp
More file actions
41 lines (34 loc) · 962 Bytes
/
button.cpp
File metadata and controls
41 lines (34 loc) · 962 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
39
40
41
#include "Button.h"
#include <QGraphicsTextItem>
#include <QBrush>
Button::Button(QString name, QGraphicsItem *parent): QGraphicsRectItem(parent)
{
setRect(0,0,200,50);
QBrush brush;
brush.setStyle(Qt::SolidPattern);
brush.setColor(Qt::gray);
setBrush(brush);
text = new QGraphicsTextItem(name,this);
int xPos = rect().width()/2 - text->boundingRect().width()/2;
int yPos = rect().height()/2 - text->boundingRect().height()/2;
text->setPos(xPos,yPos);
setAcceptHoverEvents(true);
}
void Button::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
emit clicked();
}
void Button::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
QBrush brush;
brush.setStyle(Qt::SolidPattern);
brush.setColor(Qt::white);
setBrush(brush);
}
void Button::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
QBrush brush;
brush.setStyle(Qt::SolidPattern);
brush.setColor(Qt::gray);
setBrush(brush);
}