-
Notifications
You must be signed in to change notification settings - Fork 0
/
Button.cpp
40 lines (36 loc) · 1.03 KB
/
Button.cpp
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
#include <Button.h>
#include <QBrush>
#include <QGraphicsTextItem>
#include <QFont>
Button::Button(QString name, QGraphicsItem *parent): QGraphicsRectItem(parent)
{
setRect(0,0,200,50);
QBrush brush;
brush.setStyle(Qt::SolidPattern);
brush.setColor(Qt::cyan);
setBrush(brush);
cc = new QGraphicsTextItem(name,this);
int xPos = rect().width()/2- cc->boundingRect().width()/2;
int yPos = rect().height()/2-cc->boundingRect().height()/2;
cc->setPos(xPos,yPos);
cc->setFont(QFont("times",10));
setAcceptHoverEvents(true);
}
void Button::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
emit clicked();
}
void Button::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
QBrush brush;
brush.setStyle(Qt::SolidPattern);
brush.setColor(Qt::darkCyan);
setBrush(brush);
}
void Button::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
QBrush brush;
brush.setStyle(Qt::SolidPattern);
brush.setColor(Qt::darkCyan);
setBrush(brush);
}