2020-09-01

#include "chatlist.h"
#include <QPushButton>
#include <QScrollBar>

ChatList::ChatList(QWidget *parent) : QWidget(parent)
{
    initComponent();
}

ChatList::~ChatList()
{
    delete m_pChatListScrollArea;
}

void ChatList::initComponent()
{
    this->m_pChatListScrollArea = new QScrollArea(this);
    this->m_pChatListScrollArea->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
    this->m_pChatListScrollArea->setWidgetResizable(true);
    m_pChatListScrollArea->setStyleSheet("QScrollArea {background-color:transparent;}");

    m_pChatListScrollArea->viewport()->setStyleSheet("background-color:transparent;");
    m_pChatListScrollArea->horizontalScrollBar()->setStyleSheet("QScrollBar{height:0px;}");
    m_pChatListScrollArea->verticalScrollBar()->setStyleSheet("QScrollBar{width:0px;}");

    //setValue()操作滚动条
    this->m_pSCVLayout = new QVBoxLayout(this);
    this->m_pSCVLayout->setSizeConstraint(QVBoxLayout::SetMinAndMaxSize);

    QWidget* widget = new QWidget(this);
    widget->setMinimumSize(72, 32);
    widget->setMaximumSize(80,32);

    int i = 0;
    QString str("pushButton %1");
    QPushButton* pushButton;
    for (i=0; i<100; ++i)
    {
        pushButton = new QPushButton(str.arg(i+1), widget);
        pushButton->setMinimumSize(pushButton->size());
        this->m_pSCVLayout->addWidget(pushButton);
    }
    widget->setLayout(this->m_pSCVLayout);
    this->m_pChatListScrollArea->setWidget(widget);
}




#ifndef CHATLIST_H
#define CHATLIST_H
#include <QWidget>
#include <QScrollArea>
#include <QVBoxLayout>

class ChatList : public QWidget
{
    Q_OBJECT
public:
    explicit ChatList(QWidget *parent = 0);
    ~ChatList();

private:
    void initComponent();

signals:

public slots:

private:
    QScrollArea* m_pChatListScrollArea;
    QVBoxLayout* m_pSCVLayout;
};


#endif // CHATLIST_H



#include "chatlist.h"

#include <QApplication>
#include <QVBoxLayout>

int main(int argc, char* argv[])
{
    QApplication app(argc, argv);

    ChatList chatList;
    chatList.show();

    return app.exec();
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值