Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QScrollArea - how to make it smaller?



  • Hey

    I'm trying to build a tight packet scrollArea, something that works like tabWidget but with different usage/needs/etc...

    I mocked up a quick example of the .ui to show what I have now. But I struggle to make the scrollarea smaller. Push the scroll bar just under the buttons and push buttons to top of the scrollArea but sadly no luck... can any1 help me out with it ?

    Even for other purposes I seem to never be able to remove the 4-5 pixels of scrollArea frame that I get when I setWidget()to it... how can I control it ?

    <?xml version="1.0" encoding="UTF-8"?>
    <ui version="4.0">
     <class>Form</class>
     <widget class="QWidget" name="Form">
      <property name="geometry">
       <rect>
        <x>0</x>
        <y>0</y>
        <width>308</width>
        <height>406</height>
       </rect>
      </property>
      <property name="windowTitle">
       <string>Form</string>
      </property>
      <layout class="QVBoxLayout" name="verticalLayout_2">
       <property name="spacing">
        <number>1</number>
       </property>
       <property name="leftMargin">
        <number>1</number>
       </property>
       <property name="topMargin">
        <number>1</number>
       </property>
       <property name="rightMargin">
        <number>1</number>
       </property>
       <property name="bottomMargin">
        <number>1</number>
       </property>
       <item>
        <widget class="QWidget" name="widget" native="true">
         <layout class="QVBoxLayout" name="verticalLayout">
          <property name="spacing">
           <number>10</number>
          </property>
          <property name="leftMargin">
           <number>1</number>
          </property>
          <property name="topMargin">
           <number>1</number>
          </property>
          <property name="rightMargin">
           <number>1</number>
          </property>
          <property name="bottomMargin">
           <number>1</number>
          </property>
          <item>
           <widget class="QScrollArea" name="scrollArea">
            <property name="sizePolicy">
             <sizepolicy hsizetype="Expanding" vsizetype="Minimum">
              <horstretch>0</horstretch>
              <verstretch>0</verstretch>
             </sizepolicy>
            </property>
            <property name="widgetResizable">
             <bool>true</bool>
            </property>
            <widget class="QWidget" name="scrollAreaWidgetContents">
             <property name="geometry">
              <rect>
               <x>0</x>
               <y>0</y>
               <width>450</width>
               <height>52</height>
              </rect>
             </property>
             <property name="sizePolicy">
              <sizepolicy hsizetype="Preferred" vsizetype="Minimum">
               <horstretch>0</horstretch>
               <verstretch>0</verstretch>
              </sizepolicy>
             </property>
             <layout class="QHBoxLayout" name="horizontalLayout">
              <property name="spacing">
               <number>0</number>
              </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="QPushButton" name="pushButton">
                <property name="text">
                 <string>PushButton</string>
                </property>
               </widget>
              </item>
              <item>
               <widget class="QPushButton" name="pushButton_3">
                <property name="text">
                 <string>PushButton</string>
                </property>
               </widget>
              </item>
              <item>
               <widget class="QPushButton" name="pushButton_4">
                <property name="text">
                 <string>PushButton</string>
                </property>
               </widget>
              </item>
              <item>
               <widget class="QPushButton" name="pushButton_5">
                <property name="text">
                 <string>PushButton</string>
                </property>
               </widget>
              </item>
              <item>
               <widget class="QPushButton" name="pushButton_6">
                <property name="text">
                 <string>PushButton</string>
                </property>
               </widget>
              </item>
              <item>
               <widget class="QPushButton" name="pushButton_7">
                <property name="text">
                 <string>PushButton</string>
                </property>
               </widget>
              </item>
             </layout>
            </widget>
           </widget>
          </item>
          <item>
           <widget class="QScrollArea" name="scrollArea_2">
            <property name="widgetResizable">
             <bool>true</bool>
            </property>
            <widget class="QWidget" name="scrollAreaWidgetContents_2">
             <property name="geometry">
              <rect>
               <x>0</x>
               <y>0</y>
               <width>302</width>
               <height>319</height>
              </rect>
             </property>
             <layout class="QGridLayout" name="gridLayout">
              <item row="0" column="0">
               <widget class="QPushButton" name="pushButton_8">
                <property name="text">
                 <string>PushButton</string>
                </property>
               </widget>
              </item>
              <item row="0" column="1">
               <widget class="QPushButton" name="pushButton_11">
                <property name="text">
                 <string>PushButton</string>
                </property>
               </widget>
              </item>
              <item row="1" column="0">
               <widget class="QPushButton" name="pushButton_9">
                <property name="text">
                 <string>PushButton</string>
                </property>
               </widget>
              </item>
              <item row="1" column="1">
               <widget class="QPushButton" name="pushButton_10">
                <property name="text">
                 <string>PushButton</string>
                </property>
               </widget>
              </item>
             </layout>
            </widget>
           </widget>
          </item>
         </layout>
        </widget>
       </item>
      </layout>
     </widget>
     <resources/>
     <connections/>
    </ui>
    

  • Lifetime Qt Champion

    Hi,

    Do you mean you want to give in a fixed width/height/size ?



  • @SGaist said in QScrollArea - how to make it smaller?:

    Hi,

    Do you mean you want to give in a fixed width/height/size ?

    There seems to be a frame around setWidget(widget) widget... like 5-10 pixels fro meach side. Changing layout margins/etc of qscrollarea does not help.


  • Lifetime Qt Champion

    Hi
    Are you sure you removed the margins on the right layout?
    if i set margins to zero for the layout on the content widget, its pretty tight
    alt text

    update:
    yep you forgot the second layout , it seems. or did it to other scrollarea.
    (there are 2 )

    alt text


Log in to reply