代码拉取完成,页面将自动刷新
#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);
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。