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. How to get QHBoxLayout or QVBoxLayout to auto expanding with its parent QWidget in .ui file
Qt 6.11 is out! See what's new in the release blog

How to get QHBoxLayout or QVBoxLayout to auto expanding with its parent QWidget in .ui file

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 2.5k 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.
  • L Offline
    L Offline
    lygstate
    wrote on last edited by
    #1

    I didn't found any way to do that.

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lygstate
      wrote on last edited by
      #2

      Comes with a result, the QVBoxLayout 's parent should be the TopWidget,
      then when we resize the widget, the QVBoxLayout will auto-resize with it's parent widget, that's nice.

      @
      <?xml version="1.0" encoding="UTF-8"?>
      <ui version="4.0">
      <class>GroundMain</class>
      <widget class="QWidget" name="GroundMain">
      <property name="geometry">
      <rect>
      <x>0</x>
      <y>0</y>
      <width>960</width>
      <height>540</height>
      </rect>
      </property>
      <property name="windowTitle">
      <string>控制台%1</string>
      </property>
      <property name="styleSheet">
      <string notr="true">
      QWidget#widgetA{
      background:green;
      padding: 0px;
      border:0px;
      margin:0px 0px 0px 0px;
      }

      QWidget#widgetB{
      background:blue;
      padding: 0px;
      border:0px;
      margin:0px 0px 0px 0px;
      }

      QWidget#GroundMain{
      border:0px
      padding: 0px;
      margin:0px 0px 0px 0px;
      background:red;
      }

      </string>
      </property>
      <layout class="QHBoxLayout" name="horizontalLayout">
      <property name="spacing">
      <number>0</number>
      </property>
      <property name="sizeConstraint">
      <enum>QLayout::SetMaximumSize</enum>
      </property>
      <property name="leftMargin">
      <number>0</number>
      </property>
      <property name="topMargin">
      <number>0</number>
      </property>
      <property name="rightMargin">
      <number>0</number>
      </property>
      <property name="bottomMargin">
      <number>0</number>
      </property>
      <item>
      <widget class="QWidget" name="widgetA" native="true">
      <property name="sizePolicy">
      <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
      <horstretch>1</horstretch>
      <verstretch>0</verstretch>
      </sizepolicy>
      </property>
      </widget>
      </item>
      <item>
      <widget class="QWidget" name="widgetB" native="true">
      <property name="sizePolicy">
      <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
      <horstretch>1</horstretch>
      <verstretch>0</verstretch>
      </sizepolicy>
      </property>
      </widget>
      </item>
      </layout>
      </widget>
      <resources/>
      <connections/>
      </ui>

      @

      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