1 Star 0 Fork 2

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

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
talkmsglist.cpp 1.67 KB
一键复制 编辑 原始数据 按行查看 历史
UNSTOPPABLE 提交于 2022-08-19 16:11 . 首次提交
#include "talkmsglist.h"
#include <QDebug>
#include <QAction>
#include <QIcon>
#include <QHostAddress>
#include "contactlist.h"
#include "talkmsglistitem.h"
TalkMsgList::TalkMsgList(QListWidget *parent) : QListWidget(parent)
{
setFocusPolicy(Qt::NoFocus);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
}
void TalkMsgList::mousePressEvent(QMouseEvent *event)
{
QListWidget::mousePressEvent(event);
currentItem = this->itemAt(mapFromGlobal(QCursor::pos()));
if(event->button()==Qt::LeftButton&&currentItem!=NULL){
QWidget* pwig = this->itemWidget(currentItem);
QList<ContactInfo*> contactInfoList = pwig->findChildren<ContactInfo*>();
for (int i=0;i<contactInfoList.size();i++) {
qDebug()<<contactInfoList[0];
emit contactItemClick(contactInfoList[0]);
}
}
}
void TalkMsgList::slotAddMsg(ContactInfo *contactInfo,bool isMe)
{
TalkMsgListItem *msgItem=new TalkMsgListItem(isMe);
msgItem->avatarPath=contactInfo->avatarPath;
msgItem->nickName->setText(contactInfo->sourceHostUserName);
msgItem->hostName->setText(contactInfo->msgPayLoad);
contactInfo->setParent(msgItem);
msgItem->contactInfo=contactInfo;
int textContHeight=msgItem->hostName->sizeHint().height();
msgItem->hostName->setMinimumWidth(msgItem->hostName->sizeHint().width());
msgItem->hostName->setMaximumWidth(msgItem->hostName->sizeHint().width());
QListWidgetItem *newItem = new QListWidgetItem();
QSize itemSize=QSize();
itemSize.setHeight(40+textContHeight);
newItem->setSizeHint(itemSize);
this->addItem(newItem);
this->setItemWidget(newItem, msgItem);
this->scrollToBottom();
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/spyhooky/lan-chat-software-based-on-qt5.git
[email protected]:spyhooky/lan-chat-software-based-on-qt5.git
spyhooky
lan-chat-software-based-on-qt5
毕设大作业基于qt5开发的局域网聊天软件
master

搜索帮助