Qt, Designer creates scrollAreaWidgetContents in scrollArea and I cannot resize my label

I dragged the scroll pane into the constructor, then I dragged the label (imageLabel, for setPixmap). Then I right-clicked and set the layout to be a grid.

scrollArea = new QS..... scrollAreaWidgetContents = new QWidget(); gridlayout = new QGri..(scrollAreaWidgetContents); imageLabel = new QLabel(scrollAreaWidgetContents); gridLayout->addWidget(imageLabel,.....); scrollArea->setWidget(scrollAreaWidgetContents); 

So, the developer created the code above, several parts remain, and now I have ui-> imageLabel-> setPixmap in my code set and am trying to do ui-> imageLabel-> resize (200,200). But the image is always at full size 1600x1400 pixels).

Code examples around the network, it seems like they set imageLabel directly to scrollArea and omit scrollAreaWidgetContents? But I, it seems, did not get this from the designer?

+4
source share
2 answers

resize ignored most of the time when the widget is inside the layout.

Instead, you can use setFixedSize or setMinimumSize to make the size or size smaller than the image.

You also need to set the QLabel scaledContents to True (in the designer or using QLabel::setScaledContents ) to scale the image to the size of the label.

0
source

Create a layout in the designer. Change the layout borders to zero. This should lead to the same result as removing scrollAreaWidgetContents from the chain, but still doable through the constructor.

0
source

All Articles