I do a text output in QLabel from a database. In different cases, the text may be a lot, but it may not be at all.

To do this, I created a QScrollArea in the designer, and I put a QLabel inside, in which the text should be displayed. At the same time, the scroll depends on the size of the QLabel , even if there is no text at all - the scroll appears.

I tried different sizePolicy , set the minimum size of QLabel , nothing helps.

What needs to be done to adjust the size of the QLabel to the size of the text?

  • @ alexis031182 I use it, I made a mistake in the text. - Artyom Paletsky
  • Is the widgetResizable property widgetResizable to true ? - alexis031182
  • @ alexis031182 tried and so and so. If true - then the scroll does not appear at all - Artem Paletsky

1 answer 1

Well, sort of, I did it.

An example in the designer

The idea is that after adding a QScrollArea to the form, you first need to add the QLayout Placement QLayout , and only then QLabel .

  • I tried to do this, anyway, the scroll depends on the size of scrollAreaWidgetContents , which is created along with QScrollArea . - Artyom Paletsky
  • Then I don’t quite understand what you want to do. - alexis031182
  • I want the scroll to depend on QLabel content, since the text is output from the database and can be of different sizes. - Artyom Paletsky
  • So it depends on me. If there is no text or completely fits into the drawing area, the scroll bars disappear. If there is not enough space horizontally, vertically, or in both directions, the corresponding bars reappear. - alexis031182
  • one
    Here is the project . - alexis031182