mirror of
https://gitee.com/Zhaoxin59/my-chat_-client.git
synced 2026-02-14 00:51:48 +08:00
116 lines
4.2 KiB
C++
116 lines
4.2 KiB
C++
#include "groupsessiondetailwidget.h"
|
|
|
|
GroupSessionDetailWidget::GroupSessionDetailWidget(QWidget *parent)
|
|
: QDialog(parent)
|
|
{
|
|
//设置窗口的基本属性
|
|
this->setFixedSize(410, 600);
|
|
this->setWindowTitle("群组详情");
|
|
this->setWindowIcon(QIcon(":resource/image/logo.png"));
|
|
this->setStyleSheet("QDialog { background-color: rgb(255, 255, 255); }");
|
|
this->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
//创建界面布局管理器
|
|
QVBoxLayout* vlayout = new QVBoxLayout();
|
|
vlayout->setSpacing(10);
|
|
vlayout->setContentsMargins(50, 20, 50, 50);
|
|
vlayout->setAlignment(Qt::AlignTop);
|
|
this->setLayout(vlayout);
|
|
|
|
//创建滚动区域
|
|
//创建qscrollarea的对象
|
|
QScrollArea* scrollArea = new QScrollArea();
|
|
scrollArea->setWidgetResizable(true);
|
|
scrollArea->verticalScrollBar()->setStyleSheet("QScrollBar:vertical { width: 2px; background-color: rgb(255, 255, 255); }");
|
|
scrollArea->horizontalScrollBar()->setStyleSheet("QScrollBar:horizontal { height: 0; }");
|
|
scrollArea->setFixedSize(310, 350);
|
|
scrollArea->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
|
scrollArea->setStyleSheet("QWidget { background-color: transparent; border: none; }");
|
|
|
|
//创建一个qscrollarea的内部的qwidget
|
|
QWidget* container = new QWidget();
|
|
scrollArea->setWidget(container);
|
|
|
|
//给container添加一个网格布局
|
|
glayout = new QGridLayout();
|
|
glayout->setSpacing(0);
|
|
glayout->setContentsMargins(0, 0, 0, 0);
|
|
glayout->setAlignment(Qt::AlignTop | Qt::AlignLeft);
|
|
container->setLayout(glayout);
|
|
|
|
//把滚动区域, 添加到布局管理器中
|
|
vlayout->addWidget(scrollArea);
|
|
|
|
//添加按钮
|
|
AvatarItem* addBtn = new AvatarItem(QIcon(":/resource/image/cross.png"), "添加");
|
|
glayout->addWidget(addBtn, 0, 0);
|
|
|
|
//添加群聊名称
|
|
QLabel* groupNameTag = new QLabel();
|
|
groupNameTag->setText("群聊名称");
|
|
groupNameTag->setStyleSheet("QLabel {font-weight: 700; font-size: 16px;}");
|
|
groupNameTag->setFixedHeight(50);
|
|
groupNameTag->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
|
|
// 设置文字在 QLabel 内部的对齐方式.
|
|
groupNameTag->setAlignment(Qt::AlignBottom);
|
|
// 这里设置的 QLabel 在布局管理器中的对齐方式.
|
|
vlayout->addWidget(groupNameTag);
|
|
|
|
//添加群聊的真实名字和修改按钮
|
|
//创建水平布局
|
|
QHBoxLayout* hlayout = new QHBoxLayout();
|
|
hlayout->setSpacing(0);
|
|
hlayout->setContentsMargins(0, 0, 0, 0);
|
|
vlayout->addLayout(hlayout);
|
|
|
|
//创建群聊名字的label
|
|
QLabel* groupNameLabel = new QLabel();
|
|
groupNameLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
|
|
groupNameLabel->setFixedHeight(50);
|
|
groupNameLabel->setStyleSheet("QLabel { font-size: 18px; }");
|
|
hlayout->addWidget(groupNameLabel);
|
|
|
|
//创建修改按钮
|
|
QPushButton* modifyBtn = new QPushButton();
|
|
modifyBtn->setFixedSize(30, 30);
|
|
modifyBtn->setIconSize(QSize(20, 20));
|
|
modifyBtn->setIcon(QIcon(":/resource/image/modify.png"));
|
|
modifyBtn->setIcon(QIcon(":/resource/image/modify.png"));
|
|
modifyBtn->setStyleSheet("QPushButton { border: none; background-color: transparent; } QPushButton:pressed { background-color: rgb(230, 230, 230); }");
|
|
hlayout->addWidget(modifyBtn, 0, Qt::AlignRight | Qt::AlignVCenter);
|
|
|
|
// 退出群聊按钮
|
|
QPushButton* exitGroupBtn = new QPushButton();
|
|
exitGroupBtn->setText("退出群聊");
|
|
exitGroupBtn->setFixedHeight(50);
|
|
exitGroupBtn->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
|
QString btnStyle = "QPushButton { border: 1px solid rgb(90, 90, 90); border-radius: 5px; background-color: transparent; color: rgb(0, 0, 0); }";
|
|
btnStyle += "QPushButton:pressed { background-color: rgb(230, 230, 230); }";
|
|
exitGroupBtn->setStyleSheet(btnStyle);
|
|
vlayout->addWidget(exitGroupBtn);
|
|
|
|
|
|
#if TEST_UI
|
|
groupNameLabel->setText("人类吃喝行为研究小组");
|
|
QIcon avatar(":/resource/image/defaultAvatar.png");
|
|
for (int i = 0; i < 20; ++i) {
|
|
AvatarItem* item = new AvatarItem(avatar, "张三" + QString::number(i));
|
|
this->addMember(item);
|
|
}
|
|
#endif
|
|
}
|
|
|
|
void GroupSessionDetailWidget::addMember(AvatarItem* avatarItem)
|
|
{
|
|
//拿到滚动区域的布局管理器
|
|
const int MAX_COL = 4;
|
|
if (curCol >= MAX_COL) {
|
|
// 换行操作
|
|
++curRow;
|
|
curCol = 0;
|
|
}
|
|
glayout->addWidget(avatarItem, curRow, curCol);
|
|
++curCol;
|
|
|
|
}
|