1 Star 8 Fork 2

UNSTOPPABLE/ 毕设大作业基于qt5开发的局域网聊天软件

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
talkmsglistitem.cpp 2.45 KB
一键复制 编辑 原始数据 按行查看 历史
UNSTOPPABLE 提交于 2022-08-19 16:11 . 首次提交
#include "talkmsglistitem.h"
#include "talkui.h"
#include <QHBoxLayout>
#include <QPainter>
#include <QSizePolicy>
TalkMsgListItem::TalkMsgListItem(bool isMe, QWidget *parent) : QWidget(parent)
{
initUi(isMe);
}
void TalkMsgListItem::initUi(bool isMe)
{
nickName=new QLabel(this);
nickName->setFixedHeight(20);
nickName->setAlignment(Qt::AlignRight);
nickName->setStyleSheet("QLabel{ border:none;color:black;font:13pt;}");
avatar=new QWidget(this);
avatar->setFixedSize(30,30);
avatar->installEventFilter(this);
hostName=new QLabel(this);
hostName->setStyleSheet("QLabel{ border:none;background: #ffffff;color:black;font:15pt;padding:6px 10px;}");
hostName->setWordWrap(true);
hostName->setAlignment(Qt::AlignLeft);
hostName->setTextInteractionFlags(Qt::TextSelectableByMouse);
hostName->setCursor(Qt::IBeamCursor);
QHBoxLayout *layoutH = new QHBoxLayout;
layoutH->setSpacing(0);
layoutH->setContentsMargins(16,10,16,10);
QWidget *userContent= new QWidget();
userContent->setStyleSheet("QWidget{ border:none;}");
userContent->setFixedWidth(30);
QVBoxLayout *layoutV1 = new QVBoxLayout;
layoutV1->addWidget(avatar);
layoutV1->setMargin(0);
layoutV1->setSpacing(0);
layoutV1->addSpacerItem(new QSpacerItem(20, 20,QSizePolicy::Expanding,QSizePolicy::Expanding));
userContent->setLayout(layoutV1);
layoutH->addWidget(userContent);
QVBoxLayout *layoutV = new QVBoxLayout;
layoutV->setMargin(0);
layoutV->setSpacing(0);
layoutV->setContentsMargins(9,0,9,0);
layoutV->addWidget(nickName);
QWidget *msgContent= new QWidget();
msgContent->setStyleSheet("QWidget{ border:none;}");
QVBoxLayout *layoutV2 = new QVBoxLayout;
layoutV2->setMargin(0);
layoutV2->setSpacing(0);
layoutV2->addWidget(hostName);
msgContent->setLayout(layoutV2);
layoutV->addWidget(msgContent);
layoutH->addLayout(layoutV);
this->setLayout(layoutH);
if(isMe){
this->setLayoutDirection(Qt::RightToLeft);
return;
}
nickName->setAlignment(Qt::AlignLeft);
this->setLayoutDirection(Qt::LeftToRight);
}
bool TalkMsgListItem::eventFilter(QObject *obj, QEvent *event)
{
if(obj == avatar)
{
if(event->type() == QEvent::Paint)
{
QPainter painter(avatar);
painter.drawPixmap(avatar->rect(), QPixmap(":/img/avatar1.png"));
}
}
return QWidget::eventFilter(obj, event);
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/UnStoppableeee/lan-chat-software-based-on-qt5.git
[email protected]:UnStoppableeee/lan-chat-software-based-on-qt5.git
UnStoppableeee
lan-chat-software-based-on-qt5
毕设大作业基于qt5开发的局域网聊天软件
master

搜索帮助