Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding scrollbars to QDockWidgets area

Tags:

c++

qt

For my Qt application, I have used dock widgets, but enabling too many dockwidgets causes them to flow out of the screen at the bottom. How do I add a scrollbar to the whole dockwidget area?

Here's an example:

Code of a dock widget :

QDockWidget *imageDock = new QDockWidget(i18n("Image"), this);
imageDock->setObjectName("ImageDock");
ImageChooserWidget *imageChooserWidget = new ImageChooserWidget(this);
imageDock->setWidget(imageChooserWidget);
addDockWidget(Qt::RightDockWidgetArea, imageDock);
m_dockWidgets.append(imageDock);
actionCollection()->addAction("show_image_dock", imageDock->toggleViewAction());
imageDock->setVisible(false);
connect(m_vocabularyView, SIGNAL(translationChanged(KEduVocExpression*, int)),
imageChooserWidget, SLOT(setTranslation(KEduVocExpression*, int)));

Also I have this before hand:

setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
like image 394
R4chi7 Avatar asked Jul 15 '26 14:07

R4chi7


1 Answers

Create a QScrollArea, put it into the dock widget and put your contents into the scroll area. You may need to call scrollArea->setWidgetResizable(true) to make it to resize your contents properly.

like image 168
Pavel Strakhov Avatar answered Jul 18 '26 00:07

Pavel Strakhov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!