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. Dead space at bottom of QToolBar
Forum Updated to NodeBB v4.3 + New Features

Dead space at bottom of QToolBar

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 342 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.
  • PerdrixP Offline
    PerdrixP Offline
    Perdrix
    wrote on last edited by
    #1

    My toolbar has unnecessary space at the bottom below the last tool button:

    fdbe6745-fbdd-4763-9940-ef053e6ea368-image.png

    How to get rid?

    1 Reply Last reply
    0
    • PerdrixP Offline
      PerdrixP Offline
      Perdrix
      wrote on last edited by Perdrix
      #2

      I now know what changes in my code resulted in this dead space, but I don't know how to fix it.

      If I use this:

      constexpr int iconpixels = 48;
      QString styleSheet(QString(
          "QToolBar "
          "{background-color: rgba(255,255,255,205); "
          "border-radius: %1px;} "
          "QToolButton "
              "{max-width: %2px; "
              "max-height: %2px; "
              "border: 0px;};"
          )
          .arg(radius).
          .arg(iconpixels+2)
      );
      t.setStyleSheet(styleSheet);   // t is the QToolBar
      

      The I get the dead space.

      If OTOH, I use this:

          QString styleSheet(QString(
              "QToolBar "
              "{background-color: rgba(255,255,255,205); "
              "border-radius: %1px;};"
              )
              .arg(radius)
          );
          t.setStyleSheet(styleSheet);
      

      Then I don't get the dead space and tool bar looks like this:

      1dc8baa2-39b7-47be-8e2c-53bfa8a18952-image.png

      1 Reply Last reply
      0
      • B Offline
        B Offline
        Bonnie
        wrote on last edited by Bonnie
        #3

        I guess you call adjustSize before setStyleSheet.
        adjustSize will resize the widget to its size hint. But the size hint changes after you set style sheet. So you should call it after that.
        You know what, replace adjustSize() with layout()->setSizeConstraint(QLayout::SetFixedSize), then you don't need to worry about when to call it.
        Also, since you end up subclassing the QToolBar but don't seem to need the QToolBar functions, how about subclassing a normal QWidget with 4 QToolButtons in its QVBoxLayout?
        (The tool buttons should be set to auto raise.)
        I think that kind of ui will be easier to customize than a toolbar.

        1 Reply Last reply
        0
        • PerdrixP Offline
          PerdrixP Offline
          Perdrix
          wrote on last edited by
          #4

          I've come to the conclusion that this was just going round in circles as setting the stylesheet changed the parameters for adjustSize(). Problem is that if I called adjustSize after setting the style, I lost the nice rounded corners even though the style asks for them.

          So I've just removed the styling of the ToolButtons and accepted the version that uses the translucent blue/grey rectangles as hints, which is close enough to what the original Windows custom control looked like.

          Thanks again for your help @Bonnie

          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