#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();
}