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. QLabel won't fit an image without margins
Forum Updated to NodeBB v4.3 + New Features

QLabel won't fit an image without margins

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 2.1k 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.
  • W Offline
    W Offline
    WhatIf
    wrote on last edited by
    #1

    I create two labels on a vertical layout using Qt designer. The top label has a image and the lower label has text. For both labels, I right clicked > Layout Alignment > Center Horizontally, Top.

    The problem I have is the top label which has the image has a big space separating it from the lower label. I selected it and then clicked geometry in the right panel, it expanded to show x, y, width, and height. The width x height is 327 x 78. The actual dimension of the image is 284 x 67. I can't modify the values because they are grayed out.

    How can I eliminated the excess space in the label not used by the image so that the top and lower labels look as if they were almost one label without the big space separating them?

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

      Hi
      for the layout, check the layout margins.
      there is also one that defines the space between widgets.
      (layoutHorizontalSpaceng)

      W 1 Reply Last reply
      0
      • mrjjM mrjj

        Hi
        for the layout, check the layout margins.
        there is also one that defines the space between widgets.
        (layoutHorizontalSpaceng)

        W Offline
        W Offline
        WhatIf
        wrote on last edited by
        #3

        @mrjj

        layoutLeftMargin 0
        layoutTopMargin 0
        layoutRightMargin 0
        layoutBottomMargin 0

        layoutSpacing 6

        I changed the layoutSpacing to 0 saved and ran the app, still get the same result.

        mrjjM kshegunovK 2 Replies Last reply
        0
        • W WhatIf

          @mrjj

          layoutLeftMargin 0
          layoutTopMargin 0
          layoutRightMargin 0
          layoutBottomMargin 0

          layoutSpacing 6

          I changed the layoutSpacing to 0 saved and ran the app, still get the same result.

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

          @mrjj said:
          also layoutHorizontalSpacing ?
          You could set Maximum Height on the label with image
          to match image dimensions.

          can u show a picture ?

          W 1 Reply Last reply
          0
          • W WhatIf

            @mrjj

            layoutLeftMargin 0
            layoutTopMargin 0
            layoutRightMargin 0
            layoutBottomMargin 0

            layoutSpacing 6

            I changed the layoutSpacing to 0 saved and ran the app, still get the same result.

            kshegunovK Offline
            kshegunovK Offline
            kshegunov
            Moderators
            wrote on last edited by kshegunov
            #5

            @WhatIf
            Hello,
            The label widget has a margin itself (the distance between the frame and the contents) that is independent of the layout's margins. Have you tried setting the label margin to be 0 as well?

            Kind regards.

            Read and abide by the Qt Code of Conduct

            W 1 Reply Last reply
            0
            • mrjjM mrjj

              @mrjj said:
              also layoutHorizontalSpacing ?
              You could set Maximum Height on the label with image
              to match image dimensions.

              can u show a picture ?

              W Offline
              W Offline
              WhatIf
              wrote on last edited by
              #6

              @mrjj

              I changed the height and width of maximumSize to that of the image dimensions and still I get the same result. When I select the label that has the image, I can't find a layoutHorizontalSpacing for it.

              Here is the link to the result when I run the program:

              gap between labels

              1 Reply Last reply
              0
              • kshegunovK kshegunov

                @WhatIf
                Hello,
                The label widget has a margin itself (the distance between the frame and the contents) that is independent of the layout's margins. Have you tried setting the label margin to be 0 as well?

                Kind regards.

                W Offline
                W Offline
                WhatIf
                wrote on last edited by
                #7

                @kshegunov

                QLabel margin is 0

                kshegunovK 1 Reply Last reply
                0
                • W WhatIf

                  @kshegunov

                  QLabel margin is 0

                  kshegunovK Offline
                  kshegunovK Offline
                  kshegunov
                  Moderators
                  wrote on last edited by
                  #8

                  @WhatIf
                  Have you put a vertical spacer at the bottom? If not the layout will always try to distribute the space between the widgets.

                  Read and abide by the Qt Code of Conduct

                  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