-
Notifications
You must be signed in to change notification settings - Fork 0
/
button.cpp
executable file
·42 lines (31 loc) · 1.04 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
41
42
#include "button.h"
Button::Button(const char text[], function<void()> callback) : callback_(callback)
{
QPen pen;
pen.setStyle(Qt::SolidLine);
pen.setColor(Qt::gray);
setPen(pen);
setRect(0,0,200,50);
button_text_ = std::make_unique<QGraphicsTextItem>(text, this);
button_text_->setFont(QFont ("Sans", 14));
button_text_->setPos(rect().width()/2 - button_text_->boundingRect().width()/2,
rect().height()/2 - button_text_->boundingRect().height()/2);
setAcceptHoverEvents(true);
}
void Button::mousePressEvent(QGraphicsSceneMouseEvent* event){
callback_();
}
void Button::hoverEnterEvent(QGraphicsSceneHoverEvent* event){
QPen pen;
pen.setStyle(Qt::SolidLine);
pen.setColor(Qt::white);
setPen(pen);
QApplication::setOverrideCursor(QCursor(Qt::PointingHandCursor));
}
void Button::hoverLeaveEvent(QGraphicsSceneHoverEvent* event){
QPen pen;
pen.setStyle(Qt::SolidLine);
pen.setColor(Qt::gray);
setPen(pen);
QApplication::restoreOverrideCursor();
}