Problem with using QScrollArea + QStackedWidget + wordwrapped QLabel.
-
Hi, I have some problem and I can't understand why is it happens.
I've gotQScrollAreawithwidgetResizableset to true.
InsideQScrollAreatheQStackedWidgetis placed which contains multiple pages.I connected to
QStackedWidget::currentChanged(int)signal in order to handle switching between tabs.
ThecurrentChanged(int)handler looks like this:void MainWidget::OnCurrentChanged(int index) { QWidget* currentWidget = ui->stackedWidget->widget(index); ui->stackedWidget->setMinimumSize(currentWidget); }Why do I need such code? Because of
QScrollArea, by defaultQStackedWidgetgets thesizeHint()of the biggest widget, in other words:
(pseudocode)stackedSizeHint.width = max( contained_widgets.width ) stackedSizeHint.height = max( contained_widgets.height )As I said before,
QStackedWidgetis placed insideQScrollArea, so without the code above,QScrollAreawould have scrolls permanently if one of the widgets needs it.
That's why I wrotecurrentChanged(int)handler.Every page of my
QStackedWidgetcontains only simpleQPushButton,QLabeland vertical spacer, and all of them are laid out inside vertical layout.
Everything worked as expected, but the problem appeared when I turned onwordWrapinQLabel. After settingQLabel'swordWrapto true, strange thing happens - useless scroll appears every time when it's not needed at all (on page which contains QLabel withwordWrapenabled).
Why? How can I fix it?I also tried to print the widgets geometry, scroll appears because of spacer which somehow keeps his size unnecessary big.
Why does it happen? Is there a solution for this problem?
Thanks.
-
Hi,
Rather than adding a spacer item, you can add a stretch after your widgets which should keep them in place and not use more space.
Hope it helps
-
Hi,
Rather than adding a spacer item, you can add a stretch after your widgets which should keep them in place and not use more space.
Hope it helps
-
If you are talking about QSpacerItem, then yes you are right but sizeHint = (0,0) doesn't look right.
Anyway can you show a minimal sample code that shows this behavior ?