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. [Solved] Restrain Height of QHBoxLayout
Forum Updated to NodeBB v4.3 + New Features

[Solved] Restrain Height of QHBoxLayout

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 14.4k Views 1 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.
  • J Offline
    J Offline
    jesuisbenjamin
    wrote on last edited by
    #1

    Hello,

    I've looked into the doc and played around with QHBoxLayout, but i can't seem to be able to restrain its size (especially it height).
    I have a layout with labels, and icons, i want it to be 25px high (not less, not more). I've tried to use 'setGeometry()' passing in a QRect and 'setHeight(25)', and then using setSizeConstraint(3). But no matter what i choose, the layout seems to take on a height of about 40 to 50. The layout's geometry().height() however shows '0' no matter what i do...
    I'm a bit confused now, could you help me?

    Thanks.
    Benjamin

    1 Reply Last reply
    0
    • EddyE Offline
      EddyE Offline
      Eddy
      wrote on last edited by
      #2

      Try this:

      Set its layoutsizeconstraint to fixedsize.

      Also the labels, icons you use in the layout should have size policy fixed.(at least one of them)

      Qt Certified Specialist
      www.edalsolutions.be

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jesuisbenjamin
        wrote on last edited by
        #3

        Thanks. It's exactly what i did:

        @self.label1 = QtGui.QLabel("hello", self)
        self.label1.setFixedHeight(24)

        self.hbox = QtGui.QHBoxLayout()
        self.hbox.addStretch(0)
        self.hbox.setSizeConstraint(QtGui.QLayout.SetFixedSize)
        self.hbox.addWidget(self.label1)

        self.setLayout(self.hbox)@

        And if i query the geometry:
        label heightis: 24
        hbox sizehint PyQt4.QtCore.QSize(72, 24)
        hbox margins:
        top: 0;
        bottom: 0
        hbox size constraint: 3
        hbox geometry:
        height: 0;
        width: 0;
        x pos: 0;
        y pos: 0;
        top: 0;
        bottom: -1

        Despite this, the height is not 24, but rather app. 40 to 50 px high.

        1 Reply Last reply
        0
        • EddyE Offline
          EddyE Offline
          Eddy
          wrote on last edited by
          #4

          it think you forgot to set
          label->setMinimumSize(QSize(50, 24));
          or something like that.

          Qt Certified Specialist
          www.edalsolutions.be

          1 Reply Last reply
          0
          • J Offline
            J Offline
            jesuisbenjamin
            wrote on last edited by
            #5

            Apparently the problem was due to the margins of the QHBoxLayout which i had to set with setContentsMargins(0, 0, 0, 0).

            Thanks.
            B.

            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