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. Layout spacing when widgets are hidden
Forum Updated to NodeBB v4.3 + New Features

Layout spacing when widgets are hidden

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 10.3k 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.
  • G Offline
    G Offline
    goocreations
    wrote on last edited by
    #1

    I have a widget with 3 text boxes underneath each other. All margins of this widget is set to 0. The default spacing is left at 6. I want the widget to have no spacing between the child widgets an its border. Hence the only place where there should be visible space is between textbox1 and textbox2; and textbox2 and textbox3. Everything looks perfect if all 3 text boxes are visible. The problem is that I want to dynamically hide the last text box. When I hide it, there is still some space left between textbox2 and the bottom of the parent widget. I assume this is the 6px spacing, since the margins are at 0px.

    When I hide textbox3, textbox2 is the last one in the widget. How can I remove the space underneath it? If I set the layout's spacing to 0, textbox1 and textbox2 are touching, which I don't want. I basically want all spacing to stay at 6px, except if the spacing is between a textbox and the parent widget.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dbzhang800
      wrote on last edited by
      #2

      HI, which Qt version and platform are you using?

      I can not reproduce this problem under Qt5 Windows Xp

      1 Reply Last reply
      0
      • G Offline
        G Offline
        goocreations
        wrote on last edited by
        #3

        Qt 5 (latest stable release) under Ubuntu.

        1 Reply Last reply
        0
        • N Offline
          N Offline
          navsystems
          wrote on last edited by
          #4

          It seems that QFormLayout does not remove spacing for invisible items which is something that I have just encountered in a fairly complex form layout with about 8 pairs of label and QLineEdit/QComboBox widgets each of which must be shown or hidden depending on selection of another ComboBox. The hidden controls take up space in the form layout and as a result it does not look quite right. Using a individual layouts e.g horizontal layout for each label/control pair and then stacking them with a vertical layout works but does not look good either as labels tend to be of differing lengths. Using a grid layout also looks rather horrible unless you take steps to make sure that the column widths are set appropriately. Clearly a form layout would be better but the extra unwanted spacing is a bit of a nightmare. Obviously one could remove and re-insert items into a form layout but the bottom line is that all of these workarounds are extra work and ideally when using we should be concentrating on our application logic and not having to write code to work around bugs in Qt.

          I suppose one possible option (not something I have properly considered) would be to create a QFormLayout subclass in order to "fix" the problem. It might be easier than some other workarounds. For now my dialog just has to live with the spacing issue, I'll have to get back to this one later!!

          For reference the following links refer to the same problem including an unclosed Qt bug report.

          http://stackoverflow.com/questions/17986164/how-to-removing-remaining-spacing-after-hide-a-row-in-qformlayout
          http://qt-project.org/forums/viewthread/8105
          https://bugreports.qt-project.org/browse/QTBUG-6864
          http://stackoverflow.com/questions/1874426/hiding-qt-widget-and-keeping-widget-space

          1 Reply Last reply
          2

          • Login

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