i add Multiple QListwidget to QscrollArea,but the scrollbar doesn't display in QscrollArea, why?
#include "mainwindow.h"
MainWindow
::MainWindow(QWidget *parent
){
widget->setLayout(rightLayout);
widget->setMinimumHeight(100);
scroll->setWidget(widget);
scroll->setWidgetResizable(true);
button->setText("Add Widget");
splitter->addWidget(button);
splitter->addWidget(scroll);
QObject::connect(button,
SIGNAL( clicked
() ),
this,
SLOT(addMyWidget
()));
this->setCentralWidget(splitter);
}
void MainWindow::addMyWidget()
{
for(int i = 0; i < 4; i++)
{
newItem->setText("aaaaaa");
listWidget->addItem(newItem);
}
rightLayout->addWidget(listWidget);
}
MainWindow::~MainWindow()
{
}
#include "mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
rightLayout = new QVBoxLayout;
QWidget *widget = new QWidget;
widget->setLayout(rightLayout);
widget->setMinimumHeight(100);
widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
QScrollArea *scroll = new QScrollArea;
scroll->setWidget(widget);
scroll->setWidgetResizable(true);
splitter = new QSplitter;
QPushButton *button = new QPushButton;
button->setText("Add Widget");
button->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
splitter->addWidget(button);
splitter->addWidget(scroll);
QObject::connect(button, SIGNAL( clicked() ), this, SLOT(addMyWidget()));
this->setCentralWidget(splitter);
}
void MainWindow::addMyWidget()
{
QListWidget *listWidget = new QListWidget;
for(int i = 0; i < 4; i++)
{
QListWidgetItem *newItem = new QListWidgetItem;
newItem->setText("aaaaaa");
listWidget->addItem(newItem);
}
listWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
rightLayout->addWidget(listWidget);
}
MainWindow::~MainWindow()
{
}
To copy to clipboard, switch view to plain text mode
Bookmarks