Thank you for your help.
I change my code as you said and get what I want.
void MainWindow::createLayerToolBar() {
...
layerToolBar = new QToolBar(tr
("Layers"));
addToolBar(Qt::RightToolBarArea, layerToolBar);
...
QWidget * layerWidget
= createLayerWidget
();
...
layerToolBar->addWidget(scrollArea);
scrollArea->setWidget(layerWidget);
scrollArea->setAlignment(Qt::AlignCenter);
scrollArea
->viewport
()->setBackgroundRole
(QPalette::Light);
scrollArea->viewport()->setAutoFillBackground(true);
scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn) ;
}
void MainWindow::createLayerToolBar() {
...
layerToolBar = new QToolBar(tr("Layers"));
addToolBar(Qt::RightToolBarArea, layerToolBar);
...
QWidget * layerWidget = createLayerWidget();
...
QScrollArea * scrollArea = new QScrollArea;
layerToolBar->addWidget(scrollArea);
scrollArea->setWidget(layerWidget);
scrollArea->setAlignment(Qt::AlignCenter);
scrollArea->viewport()->setBackgroundRole(QPalette::Light);
scrollArea->viewport()->setAutoFillBackground(true);
scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn) ;
}
To copy to clipboard, switch view to plain text mode
But now I don't understand the following.
If I wrote
scrollArea->setWidget(layerWidget);
QScrollArea * scrollArea = new QScrollArea(layerToolBar);
scrollArea->setWidget(layerWidget);
To copy to clipboard, switch view to plain text mode
the toolBar isn't appeared.
But if I wrote
layerToolBar->addWidget(scrollArea);
scrollArea->setWidget(layerWidget);
QScrollArea * scrollArea = new QScrollArea;
layerToolBar->addWidget(scrollArea);
scrollArea->setWidget(layerWidget);
To copy to clipboard, switch view to plain text mode
everything is fine. Why???
Bookmarks