mywidget.cpp
2.23 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
#include "mywidget.h"
#define defaultimg ":/Images/ChatArea/Default_headimg.png"
MyWidget::MyWidget(QWidget *parent) :
QWidget(parent)
{
}
void MyWidget::init(const QString &icon, const QString &name,
const QString &data, const QString &text,const int msgNum)
{
LabelMyHead.setStyleSheet("border-radius:5px;");
LabelMyHead.setMaximumSize(QSize(45,45));
if(icon.size() > 5)
LabelMyHead.setPixmap(QPixmap(icon).scaled(45, 45, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
else
LabelMyHead.setPixmap(QPixmap(QString(defaultimg)).scaled(45, 45, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
LabelName.setMaximumWidth(70);
LabelName.setText(name);
LabelData.setText(data);
if(text.length() > 8)
LabelText.setText(QString("%1...").arg(text.left(8)));
else
LabelText.setText(text);
LabelMsgNum.setMaximumSize(QSize(22,22));
LabelMsgNum.setMinimumSize(QSize(22,22));
if(msgNum > 0)
{
LabelMsgNum.setStyleSheet("background-color:rgba(0,0,0,0);color:rgb(255,255,255);border-image: url(:Images/Home/img_msg_num.png);");
LabelMsgNum.setAlignment(Qt::AlignCenter);
if(msgNum > 99)
LabelMsgNum.setText(QString("99+"));
else
LabelMsgNum.setText(QString("%1").arg(msgNum));
}
else
{
LabelMsgNum.setStyleSheet("background-color:rgba(0,0,0,0);");
}
QVBoxLayout *vLayout = new QVBoxLayout();
QHBoxLayout *hLayout = new QHBoxLayout();
QHBoxLayout *hLayout1 = new QHBoxLayout();
QHBoxLayout *hLayout2 = new QHBoxLayout();
hLayout->addWidget(&LabelName,1);
hLayout->addWidget(&LabelData,1);
hLayout2->addWidget(&LabelText,8);
hLayout2->addWidget(&LabelMsgNum,2);
vLayout->addLayout(hLayout,1);
vLayout->addLayout(hLayout2,1);
hLayout1->addWidget(&LabelMyHead,1);
hLayout1->addLayout(vLayout,3);
this->setLayout(hLayout1);
LabelName.setStyleSheet("background-color:rgba(0,0,0,0);");
LabelData.setStyleSheet("background-color:rgba(0,0,0,0);color:rgb(100,100,100);");
LabelText.setStyleSheet("background-color:rgba(0,0,0,0);color:rgb(100,100,100);");
LabelData.setAlignment(Qt::AlignRight);
}
void MyWidget::SetSize(int w,int h)
{
}