mirror of
https://gitee.com/Zhaoxin59/my-chat_-client.git
synced 2026-02-14 00:51:48 +08:00
fix bug
This commit is contained in:
@ -41,6 +41,7 @@ else()
|
|||||||
model/data.h
|
model/data.h
|
||||||
resource.qrc
|
resource.qrc
|
||||||
sessionfriendarea.h sessionfriendarea.cpp
|
sessionfriendarea.h sessionfriendarea.cpp
|
||||||
|
debug.h
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
6
debug.h
Normal file
6
debug.h
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#ifndef DEBUG_H
|
||||||
|
#define DEBUG_H
|
||||||
|
|
||||||
|
#define TEST_UI 1
|
||||||
|
|
||||||
|
#endif // DEBUG_H
|
||||||
@ -128,7 +128,7 @@ void MainWidget::initMidWindow()
|
|||||||
searchEdit = new QLineEdit();
|
searchEdit = new QLineEdit();
|
||||||
searchEdit->setFixedHeight(30);
|
searchEdit->setFixedHeight(30);
|
||||||
searchEdit->setPlaceholderText("搜索");
|
searchEdit->setPlaceholderText("搜索");
|
||||||
searchEdit->setStyleSheet("QLineEdit {border-radius: 5px; background-color: rgb(226, 226, 226); padding-left: 5px }");
|
searchEdit->setStyleSheet("QLineEdit { border-radius: 5px; background-color: rgb(226, 226, 226); padding-left: 5px; }");
|
||||||
|
|
||||||
addFriendBtn = new QPushButton();
|
addFriendBtn = new QPushButton();
|
||||||
addFriendBtn->setFixedSize(30, 30);
|
addFriendBtn->setFixedSize(30, 30);
|
||||||
|
|||||||
@ -1,9 +1,8 @@
|
|||||||
#include "sessionfriendarea.h"
|
#include "sessionfriendarea.h"
|
||||||
#include <QScrollBar>
|
|
||||||
#include <QVBoxLayout>
|
|
||||||
#include <QPushButton>
|
#include "debug.h"
|
||||||
#include <QGridLayout>
|
#include "model/data.h"
|
||||||
#include <QLabel>
|
|
||||||
|
|
||||||
SessionFriendArea::SessionFriendArea(QWidget *parent)
|
SessionFriendArea::SessionFriendArea(QWidget *parent)
|
||||||
: QScrollArea {parent}
|
: QScrollArea {parent}
|
||||||
@ -20,7 +19,7 @@ SessionFriendArea::SessionFriendArea(QWidget *parent)
|
|||||||
container->setFixedWidth(310);
|
container->setFixedWidth(310);
|
||||||
this->setWidget(container);
|
this->setWidget(container);
|
||||||
|
|
||||||
//给这个widget添加布局管理器,方便后续添加元素进去
|
//给这个widget添加布局管理器方便后续添加元素进去
|
||||||
QVBoxLayout* layout = new QVBoxLayout();
|
QVBoxLayout* layout = new QVBoxLayout();
|
||||||
layout->setContentsMargins(0, 0, 0, 0);
|
layout->setContentsMargins(0, 0, 0, 0);
|
||||||
layout->setSpacing(0);
|
layout->setSpacing(0);
|
||||||
@ -34,16 +33,78 @@ SessionFriendArea::SessionFriendArea(QWidget *parent)
|
|||||||
// btn->setText(Sbtn);
|
// btn->setText(Sbtn);
|
||||||
// layout->addWidget(btn);
|
// layout->addWidget(btn);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
//构造一些临时数据作为界面调试的依据
|
||||||
|
#if TEST_UI
|
||||||
|
QIcon icon(":/resource/image/defaultAv.png");
|
||||||
|
for(int i = 0; i < 30; i++) {
|
||||||
|
this->addItem(icon, "xyz" + QString::number(i), "test: last message..." + QString::number(i));
|
||||||
|
}
|
||||||
|
// LOG() << "hello world!";
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
SessionFriendItem::SessionFriendItem(QWidget* owner, const QIcon& avatar, const QString& name, const QString& text)
|
||||||
|
:owner(owner)
|
||||||
|
{
|
||||||
|
this->setFixedHeight(70);
|
||||||
|
this->setStyleSheet("QWidget { background-color: rgb(231, 231, 231); }");
|
||||||
|
|
||||||
|
//创建网格布局管理器
|
||||||
|
QGridLayout* layout = new QGridLayout();
|
||||||
|
layout->setContentsMargins(0, 0, 0, 0);
|
||||||
|
layout->setSpacing(0);
|
||||||
|
this->setLayout(layout);
|
||||||
|
|
||||||
|
//创建头像
|
||||||
|
QPushButton* avatarBtn = new QPushButton();
|
||||||
|
avatarBtn->setFixedSize(50, 50);
|
||||||
|
avatarBtn->setIconSize(QSize(50, 50));
|
||||||
|
avatarBtn->setIcon(avatar);
|
||||||
|
avatarBtn->setStyleSheet("QPushButton {border: none;} ");
|
||||||
|
avatarBtn->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||||
|
|
||||||
|
//创建名字
|
||||||
|
QLabel* nameLabel = new QLabel();
|
||||||
|
nameLabel->setText(name);
|
||||||
|
nameLabel->setStyleSheet("QLabel { font-size: 18px; fontweight: 600; }");
|
||||||
|
nameLabel->setFixedHeight(35);
|
||||||
|
nameLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||||
|
|
||||||
|
//创建消息预览的label
|
||||||
|
QLabel* messageLabel = new QLabel();
|
||||||
|
messageLabel->setText(text);
|
||||||
|
messageLabel->setStyleSheet("QLabel { font-size: 18px; fontweight: 600; }");
|
||||||
|
messageLabel->setFixedHeight(35);
|
||||||
|
messageLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||||
|
|
||||||
|
|
||||||
|
layout->addWidget(avatarBtn, 0, 0, 2, 2);
|
||||||
|
layout->addWidget(nameLabel, 0, 2, 1, 1);
|
||||||
|
layout->addWidget(messageLabel, 1, 2, 1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SessionFriendArea::clear()
|
void SessionFriendArea::clear()
|
||||||
{
|
{
|
||||||
|
QLayout* layout = container->layout();
|
||||||
|
//遍历布局管理器中的所有元素,依次从布局管理器中删除
|
||||||
|
for(int i = layout->count() - 1; i >= 0; i--) {
|
||||||
|
//takeAt就能够移除对应下标的元素,但还需要释放对象
|
||||||
|
QLayoutItem* item = layout->takeAt(i);
|
||||||
|
//进行释放
|
||||||
|
if(item->widget()) {
|
||||||
|
//把这个移除内容的widget进行释放
|
||||||
|
delete item->widget();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SessionFriendArea::addItem(const QIcon &avatar, const QString &name, const QString &text)
|
void SessionFriendArea::addItem(const QIcon &avatar, const QString &name, const QString &text)
|
||||||
{
|
{
|
||||||
|
//构造一个Item
|
||||||
|
SessionFriendItem* Item = new SessionFriendItem(this, avatar, name, text);
|
||||||
|
//将Item添加到container中
|
||||||
|
container->layout()->addWidget(Item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -3,6 +3,14 @@
|
|||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QScrollArea>
|
#include <QScrollArea>
|
||||||
|
#include <QScrollBar>
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
#include <QPushButton>
|
||||||
|
#include <QGridLayout>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QIcon>
|
||||||
|
#include <QString>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////
|
////////////////////////////////////////
|
||||||
@ -24,7 +32,7 @@ public:
|
|||||||
//
|
//
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//后续向container中的layout添加元素,就会有QScrollArea的滚动
|
//后续向container中的layout添加元素,就会有QScrollArea的滚动
|
||||||
QWidget* container;
|
QWidget* container;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|||||||
Reference in New Issue
Block a user