Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to scale a progress bar

How to scale a progress bar

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 1.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DatGK
    wrote on 16 Apr 2023, 14:38 last edited by
    #1

    Hi, I'm learning how to handle the QT Designer. I'm starting to figure out the layout, but I've stumbled upon a blocker - my layout should get rescaled at runtime, and it works for normal widgets, but doesn't work for the progress bar. It's as if the progress bar had a fixed size.

    This is how it looks initially - 3 elements in a vertical layout, progress bar in the middle.
    normal.png

    And after rescaling, only the widgets (top and bottom rectangles) get rescaled. The progress bar stays exactly the same.
    rescaled.png

    Which property is responsible for this behavior? I'm comparing the progress bar with the other widgets, but don't see that difference.

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on 16 Apr 2023, 21:09 last edited by
      #2

      The behaviour will depend a little on the widgets in the layout (i.e. a maximum or minimum size), and the settings on the layout itself.

      Assuming you are using a QGridLayout (because you don't say), and the contained widgets are mostly default, then you should look at QGridLayout::rowStretch() and QGridLayout::setRowMinimumHeight(). You should also look for minimum size limits on the progress bar or the labels either side.

      Otherwise, post more information.

      D 1 Reply Last reply 17 Apr 2023, 05:29
      0
      • C ChrisW67
        16 Apr 2023, 21:09

        The behaviour will depend a little on the widgets in the layout (i.e. a maximum or minimum size), and the settings on the layout itself.

        Assuming you are using a QGridLayout (because you don't say), and the contained widgets are mostly default, then you should look at QGridLayout::rowStretch() and QGridLayout::setRowMinimumHeight(). You should also look for minimum size limits on the progress bar or the labels either side.

        Otherwise, post more information.

        D Offline
        D Offline
        DatGK
        wrote on 17 Apr 2023, 05:29 last edited by DatGK
        #3

        @ChrisW67
        I'm not using QGridLayout in this case (alhough perhaps I should). To describe the picture in more detail:
        this is a horizontal layout, containing labels on both sides, and a QWidget in the middle. The QWidget in the middle is a vertical layout, consisting of two QWidgets, represented as the green and blue rectangles; and a progress bar.
        It looks like the progress bar has some "minimum size" parameter, but I can't find it - I just hope it's not hardcoded somewhere in the QT engine. It looks like 95px is that minimum - it doesn't scale below that. If I set the layout, so that the progress bar is above 95px, it does scale (but doesn't go below 95px, of course).
        The minimum/maximum parameters of the progress bar are not related with the size.
        progressbaroptions.png
        widget part of the progress bar states, that its minimum size is 0, just like other widgets that scale properly. Instead, its height doesn't go below this 95 pixels. Width seems to scale properly.
        progressbarwidgetoptions.png
        These are the parameters of the vertical layout, containing the progress bar, and 2 other widgets.
        layoutoptions.png

        1 Reply Last reply
        0
        • D Offline
          D Offline
          DatGK
          wrote on 26 Apr 2023, 18:20 last edited by
          #4

          It has something to do with the content of the progress bar - right now I'm sure there is some hidden, implicit minimum size that QT Designer doesn't inform me about.

          I observe the same behavior with labels, except in case of labels, I've realized that the implicit minimum size is determined by the label's text (also, wow, the "scaledcontent" field for labels is useless, the content doesn't get scaled at all, lol)

          Haven't figured this one out, left it for later. Maybe once I figure it out, I'll post the answer here.

          J 1 Reply Last reply 26 Apr 2023, 20:15
          0
          • D DatGK
            26 Apr 2023, 18:20

            It has something to do with the content of the progress bar - right now I'm sure there is some hidden, implicit minimum size that QT Designer doesn't inform me about.

            I observe the same behavior with labels, except in case of labels, I've realized that the implicit minimum size is determined by the label's text (also, wow, the "scaledcontent" field for labels is useless, the content doesn't get scaled at all, lol)

            Haven't figured this one out, left it for later. Maybe once I figure it out, I'll post the answer here.

            J Offline
            J Offline
            JonB
            wrote on 26 Apr 2023, 20:15 last edited by JonB
            #5

            @DatGK
            https://codebrowser.dev/qt5/qtbase/src/widgets/widgets/qprogressbar.cpp.html#424

                QFontMetrics fm = fontMetrics();
                QStyleOptionProgressBar opt;
                initStyleOption(&opt);
                int cw = style()->pixelMetric(QStyle::PM_ProgressBarChunkWidth, &opt, this);
                QSize size = QSize(qMax(9, cw) * 7 + fm.horizontalAdvance(QLatin1Char('0')) * 4, fm.height() + 8);
                if (opt.orientation == Qt::Vertical)
                    size = size.transposed();
            

            So qMax(9, cw) * 7 + fm.horizontalAdvance(QLatin1Char('0')) * 4.
            I think the gist is 63+-odd for the chunks (7 chunks) + 4 character 0s. Then in your case this is applied for the height instead of the width. May be quite close to 95-odd pixels.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved