-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
59 lines (46 loc) · 1.29 KB
/
mainwindow.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "mainwindow.h"
#include "MaskPath.h"
#include "ui_mainwindow.h"
#include <QPainter>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
setWindowFlags(Qt::Widget | Qt::FramelessWindowHint);
setAttribute(Qt::WA_NoSystemBackground, true);
setAttribute(Qt::WA_TranslucentBackground, true);
ui->setupUi(this);
connect(ui->pushButton, &QPushButton::clicked, this, &QCoreApplication::quit);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
int iw = 5;
QPainterPath path = MaskPath::DrawMask(this->rect(),24, iw);
painter.fillPath(path, Qt::gray);
QPainterPath inlinePath = path;
QColor border = isMouseOver ? Qt::white : Qt::gray;
border.setAlpha(250);
painter.setPen(QPen(border, iw, Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin));
painter.drawPath(inlinePath);
QWidget::paintEvent(event);
}
void MainWindow::enterEvent(QEnterEvent *event)
{
qDebug() << "inside ";
isMouseOver = true;
update();
QWidget::enterEvent(event);
}
void MainWindow::leaveEvent(QEvent *event)
{
isMouseOver = false;
update();
qDebug() << "outside ";
QWidget::leaveEvent(event);
}