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. Widgets in layout with stretch factor and no minimum size
Forum Updated to NodeBB v4.3 + New Features

Widgets in layout with stretch factor and no minimum size

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 1.2k Views 2 Watching
  • 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.
  • F Offline
    F Offline
    Fabian_Schmidt
    wrote on last edited by Fabian_Schmidt
    #1

    I add several Qlabels to a layout, they are supposed to take a certain percentage of the layout.

    //double weight = s[row][column];
    QLabel *colorLabel = new QLabel();
    QSizePolicy policy = colorLabel->sizePolicy();
    policy.setHorizontalStretch(weight * 100);
    layout.addWidget(colorLabel);
    

    The problem is, that weight can be very close to zero, in that case the label should not be displayed, it seems however that ther labels have a minimum size of 5 pixels. How can I change that?

    alt text

    The blue and brown part should not be visible according to the weight.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      In that case, set their visibility to false. That would make more sense to not show them rather than trying to give them a size "that should be zero but it's not exactly that".

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • F Offline
        F Offline
        Fabian_Schmidt
        wrote on last edited by
        #3

        That's possible, but I will have to decide on some cutoff value and when the layout resizes a label which should be hidden in a smaller parent might have to be shown. A lot of code, if I could just disable the minimum size it would be much easier and cleaner.

        mrjjM 1 Reply Last reply
        0
        • F Fabian_Schmidt

          That's possible, but I will have to decide on some cutoff value and when the layout resizes a label which should be hidden in a smaller parent might have to be shown. A lot of code, if I could just disable the minimum size it would be much easier and cleaner.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Fabian_Schmidt
          Hi
          I just tested with various widgets and it seems to come from layout and the
          way in interprets setHorizontalStretch. a value of zero do not mean zero size
          alt text
          I have not seen a setting to disable/alter this.

          F 1 Reply Last reply
          0
          • mrjjM mrjj

            @Fabian_Schmidt
            Hi
            I just tested with various widgets and it seems to come from layout and the
            way in interprets setHorizontalStretch. a value of zero do not mean zero size
            alt text
            I have not seen a setting to disable/alter this.

            F Offline
            F Offline
            Fabian_Schmidt
            wrote on last edited by Fabian_Schmidt
            #5

            @mrjj
            I tried to use a minimum of 1, while the other values were close to 10000:

            //
            policy.setHorizontalStretch(std::max(1, (int)(weight * 10000)));
            

            It still looks the same, so I think it's not just because of the zero.

            mrjjM 1 Reply Last reply
            0
            • F Fabian_Schmidt

              @mrjj
              I tried to use a minimum of 1, while the other values were close to 10000:

              //
              policy.setHorizontalStretch(std::max(1, (int)(weight * 10000)));
              

              It still looks the same, so I think it's not just because of the zero.

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by mrjj
              #6

              @Fabian_Schmidt
              Hi
              I tried again with QFrames and it seems it can be zero size unlike QLabel that would keep the 5? pixels as minimum
              alt text
              there is 3 frames here but first is zero size
              So it might be related to QLabel somehow but im not sure in which way.

              1 Reply Last reply
              1
              • F Offline
                F Offline
                Fabian_Schmidt
                wrote on last edited by
                #7

                Thanks for the answers, I was fiddling around with it, but didn't find any satisfactory solution yet.
                Basicaly what I want to achieve is something similar to a pie chart, just as a square and it should be resizable, the colors must not have a minimum size, especially not as much as 5 pixels.

                Is there any way besides writing a custom draw function?

                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