-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcardwidget.cpp
More file actions
82 lines (61 loc) · 1.86 KB
/
Copy pathcardwidget.cpp
File metadata and controls
82 lines (61 loc) · 1.86 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "cardwidget.h"
CardWidget::CardWidget(QWidget *parent):
QWidget(parent)
{
titlelabel = new QLabel(this);
contentlabel = new QLabel(this);
timelabel = new QLabel(this);
titlelabel->setMaximumSize(QSize(300,40));
contentlabel->setFixedSize(QSize(300,140));
contentlabel->setAlignment(Qt::AlignTop | Qt::AlignLeft);
timelabel->setMaximumSize(QSize(300,20));
QVBoxLayout *layout = new QVBoxLayout(this);
layout->addWidget(titlelabel);
layout->addWidget(contentlabel);
layout->addWidget(timelabel);
layout->setContentsMargins(10, 10, 10, 10); // 设置布局的边距
layout->setSpacing(0); // 设置布局中组件的间距为0
// 设置标签的样式,确保标签背景也是白色
titlelabel->setStyleSheet(
"font-size: 18pt; "
"font-weight: bold; "
"background-color: #F9F9FB; "
"border-radius: 20px;"
);
contentlabel->setStyleSheet(
"font-size: 14pt; "
"background-color: #F9F9FB; "
"border-radius: 20px;"
);
timelabel->setStyleSheet(
"font-size: 10pt; "
"color: grey; "
"background-color: #F9F9FB;"
);
contentlabel->setWordWrap(true);
}
void CardWidget::settitle(const QString &title){
titlelabel->setText(title);
}
void CardWidget::setcontent(const QString &content){
contentlabel->setText(content);
}
void CardWidget::settime(const QString &time){
timelabel->setText(time);
}
void CardWidget::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event);
QPainter painter(this);
painter.setPen(Qt::NoPen);
painter.setBrush(QBrush(QColor("#F9F9FB")));
QRect rect = this->rect();
int roundRadius = 20;
painter.drawRoundedRect(rect, roundRadius, roundRadius);
}
void CardWidget::setid(int id){
widgetid = id;
}
int CardWidget::getid(){
return widgetid;
}