Results 1 to 6 of 6

Thread: QScrollArea and layouts

  1. #1
    Join Date
    Jun 2012
    Posts
    173
    Thanks
    48
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QScrollArea and layouts

    Hello all,

    I would like if anyone can explain to me
    why in the designer and when using the QscrollArea the scroll bar are not shown, but when i run it the widget looks smaller and the scrolls are shown.

    what i have tried :
    Fix the size (width and height)
    Setting the size policy to fixed (Horizontal and vertical)
    change the layout margin of the group-box, where i have the scrollArea placed, and set all of them to zero.
    , but still the same happen.

    I have :
    A group-box with a grid layout
    then I places a scroll area on it with a grid layout as well
    then places my other widget buttons, labels and lineEdit

    see attachment for a pic in designer and in run time.
    Attached Images Attached Images

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: QScrollArea and layouts

    Can you post a sample ui file?
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QScrollArea and layouts

    It looks to me like the group box does not have a layout applied, so the QScrollArea is taking an arbitrary size and needing to show scroll bars.

  4. #4
    Join Date
    Jun 2012
    Posts
    173
    Thanks
    48
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QScrollArea and layouts

    @Santosh Reddy below is a sample ui.

    @ChrisW67 .. I do have a layout for the group-box, as I mentioned in my description the group-box has a grid layout.

    by main problem is that the widget in the designer is not the same when i run it.

    //mainwindow.ui
    Qt Code:
    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <ui version="4.0">
    3. <class>MainWindow</class>
    4. <widget class="QMainWindow" name="MainWindow">
    5. <property name="geometry">
    6. <rect>
    7. <x>0</x>
    8. <y>0</y>
    9. <width>498</width>
    10. <height>523</height>
    11. </rect>
    12. </property>
    13. <property name="windowTitle">
    14. <string>MainWindow</string>
    15. </property>
    16. <widget class="QWidget" name="centralWidget">
    17. <layout class="QGridLayout" name="gridLayout">
    18. <item row="1" column="0">
    19. <widget class="QTabWidget" name="tabWidget">
    20. <property name="currentIndex">
    21. <number>0</number>
    22. </property>
    23. <widget class="QWidget" name="tab">
    24. <attribute name="title">
    25. <string>Tab 1</string>
    26. </attribute>
    27. <layout class="QGridLayout" name="gridLayout_11">
    28. <item row="0" column="0">
    29. <widget class="QGroupBox" name="groupBox">
    30. <property name="title">
    31. <string>Main</string>
    32. </property>
    33. <layout class="QGridLayout" name="gridLayout_2">
    34. <item row="0" column="0">
    35. <widget class="QScrollArea" name="scrollArea">
    36. <property name="widgetResizable">
    37. <bool>true</bool>
    38. </property>
    39. <widget class="QWidget" name="scrollAreaWidgetContents">
    40. <property name="geometry">
    41. <rect>
    42. <x>0</x>
    43. <y>0</y>
    44. <width>450</width>
    45. <height>213</height>
    46. </rect>
    47. </property>
    48. <layout class="QGridLayout" name="gridLayout_5">
    49. <item row="0" column="0">
    50. <widget class="QGroupBox" name="groupBox_2">
    51. <property name="minimumSize">
    52. <size>
    53. <width>0</width>
    54. <height>0</height>
    55. </size>
    56. </property>
    57. <property name="maximumSize">
    58. <size>
    59. <width>5000</width>
    60. <height>5000</height>
    61. </size>
    62. </property>
    63. <property name="title">
    64. <string>Test</string>
    65. </property>
    66. <layout class="QGridLayout" name="gridLayout_3">
    67. <property name="margin">
    68. <number>0</number>
    69. </property>
    70. <item row="0" column="0">
    71. <widget class="QScrollArea" name="scrollArea_2">
    72. <property name="widgetResizable">
    73. <bool>true</bool>
    74. </property>
    75. <widget class="QWidget" name="scrollAreaWidgetContents_2">
    76. <property name="geometry">
    77. <rect>
    78. <x>0</x>
    79. <y>0</y>
    80. <width>221</width>
    81. <height>164</height>
    82. </rect>
    83. </property>
    84. <layout class="QGridLayout" name="gridLayout_4">
    85. <item row="0" column="0">
    86. <widget class="QLabel" name="label">
    87. <property name="text">
    88. <string>TextLabel</string>
    89. </property>
    90. </widget>
    91. </item>
    92. <item row="0" column="1">
    93. <widget class="QLineEdit" name="lineEdit"/>
    94. </item>
    95. <item row="1" column="0">
    96. <widget class="QLabel" name="label_2">
    97. <property name="text">
    98. <string>TextLabel</string>
    99. </property>
    100. </widget>
    101. </item>
    102. <item row="1" column="1">
    103. <widget class="QLineEdit" name="lineEdit_2"/>
    104. </item>
    105. <item row="2" column="0">
    106. <widget class="QLabel" name="label_3">
    107. <property name="text">
    108. <string>TextLabel</string>
    109. </property>
    110. </widget>
    111. </item>
    112. <item row="2" column="1">
    113. <widget class="QLineEdit" name="lineEdit_3"/>
    114. </item>
    115. <item row="3" column="0">
    116. <widget class="QLabel" name="label_4">
    117. <property name="text">
    118. <string>TextLabel</string>
    119. </property>
    120. </widget>
    121. </item>
    122. <item row="3" column="1">
    123. <widget class="QLineEdit" name="lineEdit_4"/>
    124. </item>
    125. </layout>
    126. </widget>
    127. </widget>
    128. </item>
    129. </layout>
    130. </widget>
    131. </item>
    132. <item row="0" column="1">
    133. <spacer name="horizontalSpacer_2">
    134. <property name="orientation">
    135. <enum>Qt::Horizontal</enum>
    136. </property>
    137. <property name="sizeHint" stdset="0">
    138. <size>
    139. <width>40</width>
    140. <height>20</height>
    141. </size>
    142. </property>
    143. </spacer>
    144. </item>
    145. </layout>
    146. </widget>
    147. </widget>
    148. </item>
    149. <item row="1" column="0">
    150. <spacer name="verticalSpacer">
    151. <property name="orientation">
    152. <enum>Qt::Vertical</enum>
    153. </property>
    154. <property name="sizeHint" stdset="0">
    155. <size>
    156. <width>20</width>
    157. <height>40</height>
    158. </size>
    159. </property>
    160. </spacer>
    161. </item>
    162. </layout>
    163. </widget>
    164. </item>
    165. </layout>
    166. </widget>
    167. </widget>
    168. </item>
    169. </layout>
    170. </widget>
    171. <widget class="QMenuBar" name="menuBar">
    172. <property name="geometry">
    173. <rect>
    174. <x>0</x>
    175. <y>0</y>
    176. <width>498</width>
    177. <height>23</height>
    178. </rect>
    179. </property>
    180. </widget>
    181. <widget class="QToolBar" name="mainToolBar">
    182. <attribute name="toolBarArea">
    183. <enum>TopToolBarArea</enum>
    184. </attribute>
    185. <attribute name="toolBarBreak">
    186. <bool>false</bool>
    187. </attribute>
    188. </widget>
    189. <widget class="QStatusBar" name="statusBar"/>
    190. </widget>
    191. <layoutdefault spacing="6" margin="11"/>
    192. <resources/>
    193. <connections/>
    194. </ui>
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QScrollArea and layouts

    Quote Originally Posted by jesse_mark View Post
    @ChrisW67 .. I do have a layout for the group-box, as I mentioned in my description the group-box has a grid layout.
    In your post you say you have a layout applied. My observation on the evidence presented is that this may not actually be the case. If I had dollarpound for every time someone was mistaken about their layouts...

    Now we have an actual UI file (not one that matches your screen shots though) it appears you do have a layout applied at all levels.

    by main problem is that the widget in the designer is not the same when i run it.
    The size of the space the QScrollArea has to work with is driven by the layout of its container. The presence of scroll bars is driven by the size of the QScrollArea content widget. These things are determined at run time and Designer's preview is only a close approximation because it cannot know what container you have put this widget in, or how the window manager might have sized a top-level widget. There only needs to be a pixel or two in it to make the difference.

    If you do not want scroll bars then do not put the widget in a scroll area or ensure that the scroll area's minimum size is larger than the contained widget's fixed or preferred size.

  6. The following user says thank you to ChrisW67 for this useful post:

    jesse_mark (17th September 2013)

  7. #6
    Join Date
    Jun 2012
    Posts
    173
    Thanks
    48
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QScrollArea and layouts

    Thanks,
    The fact that each QScrollArea has a ScrollArea widget content with it, which you need to set its Min size,max Size and size policy for it as well, is what was not aware off.

Similar Threads

  1. Need Help with Layouts
    By baluk in forum Qt Programming
    Replies: 2
    Last Post: 21st October 2010, 07:30
  2. Layouts
    By csvivek in forum Qt Tools
    Replies: 3
    Last Post: 7th May 2008, 07:22
  3. Replies: 2
    Last Post: 10th March 2008, 20:16
  4. Layouts
    By Dumbledore in forum Qt Tools
    Replies: 1
    Last Post: 14th October 2007, 01:01
  5. Layouts - Name cant be set
    By manivannan_1984 in forum Qt Programming
    Replies: 1
    Last Post: 14th September 2006, 18:38

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.