Files
MyChat_Client/sessionfriendarea.h
2025-05-24 12:18:28 +08:00

74 lines
1.8 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef SESSIONFRIENDAREA_H
#define SESSIONFRIENDAREA_H
#include <QWidget>
#include <QScrollArea>
#include <QScrollBar>
#include <QVBoxLayout>
#include <QPushButton>
#include <QGridLayout>
#include <QLabel>
#include <QIcon>
#include <QString>
// #include <iostream>
#include <QStyleOption>
#include <QPainter>
#include <QEnterEvent>
////////////////////////////////////////
/// 整个滚动区域的实现
////////////////////////////////////////
class SessionFriendArea : public QScrollArea
{
Q_OBJECT
public:
explicit SessionFriendArea(QWidget *parent = nullptr);
//清空区域内所有的Item
void clear();
//添加一个Item
void addItem(const QIcon& avatar, const QString& name, const QString& text);
//
private:
//后续向container中的layout添加元素,就会有QScrollArea的滚动
QWidget* container;
signals:
};
////////////////////////////////////////
/// 滚动区域的Item的实现
////////////////////////////////////////
class SessionFriendItem : public QWidget {
//可以使当前的类使用信号与槽相关的操作
Q_OBJECT
public:
SessionFriendItem(QWidget* owner, const QIcon& avatar, const QString& name, const QString& text);
//通过显式绘制控件的基础样式解决了自定义控件因未正确处理Qt样式表机制导致的QSS不生效问题
void paintEvent(QPaintEvent* event) override;
void mousePressEvent(QMouseEvent* event) override;
void enterEvent(QEvent* event) override;
void leaveEvent(QEvent* event) override;
void select();
private:
//owner 就是指向了 SessionFriendArea
QWidget* owner;
//表示当前的Item是否是选中的状态(选中时其背景色会有所不同)
bool selected = false;
};
#endif // SESSIONFRIENDAREA_H