-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbgwidget.cpp
46 lines (38 loc) · 1.08 KB
/
bgwidget.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
#include "bgwidget.h"
#include <QStylePainter>
#include <QStyleOption>
#include <QDebug>
BGWidget::BGWidget(QWidget *parent): QWidget(parent)
{
this->setStyleSheet("background-color:rgb(187, 173, 160);border-radius:5px;");
}
BGWidget::~BGWidget()
{
}
void BGWidget::paintEvent(QPaintEvent *event)
{
QStylePainter painter(this);
//用style画背景 (会使用setstylesheet中的内容)
QStyleOption opt;
opt.initFrom(this);
opt.rect=rect();
painter.drawPrimitive(QStyle::PE_Widget, opt);
painter.setPen(QColor(204,192,180));
painter.setBrush(QColor(204,192,180));
//4*4的背景矩阵
const int colWidth = 75;
const int rowHeight = 75;
const int xOffset = 10;
const int yOffset = 10;
for(int row = 0; row < 4;++row)
{
for(int col = 0; col < 4; ++col)
{
//背景方框
int x = col * colWidth + xOffset;
int y = row * rowHeight +yOffset;
painter.drawRoundRect(x,y,65,65,10,10);
}
}
QWidget::paintEvent(event);
}