2

here's a thing I'm trying to solve in QT Creator. I want to make contents of the tab widget as well as the tab widget itself to be stretchable depending on the screen size. So far I've been looking for solutions on StackOverflow but couldn't find any.

A small example:

enter image description here

As suggested in other answers I organized all contents to be in the Grid layout which has these properties.

enter image description here

In fact I even added the same Expanding value to all objects in a list. But in spite of that I'm still getting a fixed tab widget when I open it in a full screen size.

enter image description here

Any suggestions how to make the tab widget to fill all the surrounding space? Thanks in advance!

UPD 1: Sharing also my .ui https://gist.github.com/Ren22/41ca0dc0333a360775aec530d6f38a62

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Ren
  • 944
  • 1
  • 13
  • 26

1 Answers1

5

The size policy only works if the widget geometry is handled by a layout, so a solution is to set the QTabWidget as centralwidget to do it right click on an area that is outside the QTabWidget but inside the QMainWindow, then click on the icon enter image description here or enter image description here icon at the top of Qt Designer generating the following:

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>MainWindow</class>
 <widget class="QMainWindow" name="MainWindow">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>800</width>
    <height>600</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>MainWindow</string>
  </property>
  <widget class="QWidget" name="centralwidget">
   <layout class="QVBoxLayout" name="verticalLayout">
    <item>
     <widget class="QTabWidget" name="tabWidget">
      <widget class="QWidget" name="tab">
       <attribute name="title">
        <string>Tab 1</string>
       </attribute>
       <layout class="QVBoxLayout" name="verticalLayout_2">
        <item>
         <widget class="QListWidget" name="listWidget"/>
        </item>
        <item>
         <widget class="QPushButton" name="pushButton">
          <property name="text">
           <string>PushButton</string>
          </property>
         </widget>
        </item>
       </layout>
      </widget>
      <widget class="QWidget" name="tab_2">
       <attribute name="title">
        <string>Tab 2</string>
       </attribute>
      </widget>
     </widget>
    </item>
   </layout>
  </widget>
  <widget class="QMenuBar" name="menubar">
   <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
     <width>800</width>
     <height>30</height>
    </rect>
   </property>
  </widget>
  <widget class="QStatusBar" name="statusbar"/>
 </widget>
 <resources/>
 <connections/>
</ui>
eyllanesc
  • 235,170
  • 19
  • 170
  • 241