Results 1 to 6 of 6

Thread: Resizing issues, minimum size is ignored by parent widgets

  1. #1
    Join Date
    Mar 2016
    Posts
    16
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Resizing issues, minimum size is ignored by parent widgets

    I have created a Qt application with the following structure:
    *
    Qt Code:
    1. .
    2. └── QMdiArea
    3. * * └── QTabWidget
    4. * * * * └── HeaderDataBrowser
    5. * * * * * * └── QVBoxLayout
    6. * * * * * * * * └── QSplitter
    7. * * * * * * * * * * ├── QScrollArea1
    8. * * * * * * * * * * │ * └── QVBoxLayout
    9. * * * * * * * * * * │ * * * └── QTreeWidget
    10. * * * * * * * * * * └── QScrollArea2
    11. * * * * * * * * * * * * └── QVBoxLayout
    12. * * * * * * * * * * * * * * ├── QwtPlot1
    13. * * * * * * * * * * * * * * └── QwtPlot2
    To copy to clipboard, switch view to plain text mode 

    I'm having multiple issues.
    1) It appears the parent widgets of the QwtPlot widgets are ignoring the minimum size constraints. The plots just start overlapping when things get small.
    2) Even though the QwtPlot widgets are inside a QScrollArea, no scrollbars ever appear, even when resizing ridiculously small. Why?
    3) Issue 1) applies to a lot of the other parent widgets. They just ignore the minimum size constraints of their child widgets.

    *
    This video demonstrates the issues I'm having.
    1) The first run shows that the app can be scaled right down to a size that shouldn't be possible.
    2) I then set the minimum size of both QwtPlot widgets to 200, 200. Now the plots don't resize smaller than 200, 200, but they begin overlapping each other. What I really want is to restrict the app's minimum size so that doesn't happen.
    3) I then set the minimum size of the splitter widget to 300, 300 and show that the parent widgets of the application simply do not care. The scroll area gets clipped as the application is scaled down.
    *

    *
    The following code replicates this behaviour (note: I'm running Qt5. Qt4 seems to have different behaviour for some reason):

    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3.  
    4. #include <QVBoxLayout>
    5. #include <QMdiArea>
    6. #include <QSplitter>
    7. #include <QScrollArea>
    8. #include <QTreeWidget>
    9.  
    10. MainWindow::MainWindow(QWidget *parent) :
    11. QMainWindow(parent),
    12. ui(new Ui::MainWindow)
    13. {
    14. ui->setupUi(this);
    15.  
    16. ui->centralWidget->setLayout(new QVBoxLayout);
    17. QMdiArea* mdi = new QMdiArea;
    18. ui->centralWidget->layout()->addWidget(mdi);
    19.  
    20. QTabWidget* tabWidget = new QTabWidget;
    21. mdi->addSubWindow(tabWidget);
    22. tabWidget->showMaximized();
    23.  
    24. QWidget* headerDataBrowser = new QWidget;
    25. tabWidget->addTab(headerDataBrowser, "Header");
    26.  
    27. // Header data tree goes on the left side, TxSeq plots on the right
    28. QVBoxLayout* browserLayout = new QVBoxLayout;
    29. QSplitter* splitter = new QSplitter(headerDataBrowser);
    30. browserLayout->addWidget(splitter);
    31. headerDataBrowser->setLayout(browserLayout);
    32.  
    33. // Create scroll area and put a tree view inside it. Then add the scroll
    34. // area to the left side of the splitter
    35. QScrollArea* scroll = new QScrollArea;
    36. scroll->setWidgetResizable(true);
    37. splitter->addWidget(scroll);
    38. QVBoxLayout* scrollLayout = new QVBoxLayout;
    39. scroll->setLayout(scrollLayout);
    40. QTreeWidget* treeWidget = new QTreeWidget;
    41. scrollLayout->addWidget(treeWidget);
    42.  
    43. // Create layout on right side of splitter. This is where the plots are
    44. // inserted. Also add it to a scroll area, but disable horizontal
    45. // scrolling.
    46. QScrollArea* plotArea = new QScrollArea;
    47. //plotArea->setWidgetResizable(true);
    48. //plotArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOf f);
    49. splitter->addWidget(plotArea);
    50. QVBoxLayout* plotLayout = new QVBoxLayout;
    51. plotArea->setLayout(plotLayout);
    52.  
    53. // add some crap
    54. for(int i = 0; i != 20; ++i)
    55. (new QTreeWidgetItem(treeWidget))->setText(0, "Test " + QString::number(i));
    56. }
    57.  
    58. MainWindow::~MainWindow()
    59. {
    60. delete ui;
    61. }
    To copy to clipboard, switch view to plain text mode 
    *
    "People who get offended should be offended" -- Linus Torvalds

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Resizing issues, minimum size is ignored by parent widgets

    I don't think you are supposed to set a layout on a QScrollArea.
    You just set its content widget and it can have any layout you want.

    Cheers,
    _

  3. #3
    Join Date
    Mar 2016
    Posts
    16
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Resizing issues, minimum size is ignored by parent widgets

    Thanks, I tried what you said but I'm still getting the same behaviour. Even though the QTreeWidget has a minimum size, it's still possible to scale the window down to something that shouldn't be possible. The QTreeWidget simply gets clipped after it stops shrinking.

    This is the updated code:

    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent) :
    2. QMainWindow(parent),
    3. ui(new Ui::MainWindow)
    4. {
    5. ui->setupUi(this);
    6.  
    7. ui->centralWidget->setLayout(new QVBoxLayout);
    8. QMdiArea* mdi = new QMdiArea;
    9. ui->centralWidget->layout()->addWidget(mdi);
    10.  
    11. QTabWidget* tabWidget = new QTabWidget;
    12. mdi->addSubWindow(tabWidget);
    13. tabWidget->showMaximized();
    14.  
    15. QWidget* headerDataBrowser = new QWidget;
    16. tabWidget->addTab(headerDataBrowser, "Header");
    17.  
    18. // Header data tree goes on the left side, TxSeq plots on the right
    19. QVBoxLayout* browserLayout = new QVBoxLayout;
    20. headerDataBrowser->setLayout(browserLayout);
    21. QSplitter* splitter = new QSplitter;
    22. browserLayout->addWidget(splitter);
    23.  
    24. // Create scroll area and put a tree view inside it. Then add the scroll
    25. // area to the left side of the splitter
    26. QTreeWidget* treeWidget = new QTreeWidget;
    27. treeWidget->setMinimumSize(100, 100);
    28. splitter->addWidget(treeWidget);
    29.  
    30. // add some crap
    31. for(int i = 0; i != 20; ++i)
    32. (new QTreeWidgetItem(treeWidget))->setText(0, "Test " + QString::number(i));
    33. }
    To copy to clipboard, switch view to plain text mode 
    "People who get offended should be offended" -- Linus Torvalds

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Resizing issues, minimum size is ignored by parent widgets

    There is no QScrollArea in this code.

    Maybe use Designer for the widget that you then put into a tab, it makes working with splitters/layouts easier as you can test/preview more easily

    Cheers,
    _

  5. #5
    Join Date
    Mar 2016
    Posts
    16
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Resizing issues, minimum size is ignored by parent widgets

    Okay I'm really confused. I built the hierarchy in Designer and it works exactly how I expected it to work. I then programmed the hierarchy out 1:1 and guess what? The code version doesn't work. The code version can be scaled down to a size that shouldn't be possible.



    What am I missing? There must be some minor detail in the code version that I'm doing wrong, right?

    Here is the designer .ui file:
    Qt Code:
    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <ui version="4.0">
    3. <class>Form</class>
    4. <widget class="QWidget" name="Form">
    5. <property name="geometry">
    6. <rect>
    7. <x>0</x>
    8. <y>0</y>
    9. <width>563</width>
    10. <height>433</height>
    11. </rect>
    12. </property>
    13. <property name="windowTitle">
    14. <string>Form</string>
    15. </property>
    16. <layout class="QVBoxLayout" name="verticalLayout">
    17. <item>
    18. <widget class="QMdiArea" name="mdiArea">
    19. <property name="viewMode">
    20. <enum>QMdiArea::TabbedView</enum>
    21. </property>
    22. <widget class="QWidget" name="subwindow">
    23. <property name="windowTitle">
    24. <string>Subwindow</string>
    25. </property>
    26. <layout class="QVBoxLayout" name="verticalLayout_2">
    27. <item>
    28. <widget class="QTabWidget" name="tabWidget">
    29. <widget class="QWidget" name="tab">
    30. <attribute name="title">
    31. <string>Tab 1</string>
    32. </attribute>
    33. <layout class="QVBoxLayout" name="verticalLayout_3">
    34. <item>
    35. <widget class="QWidget" name="widget" native="true">
    36. <layout class="QVBoxLayout" name="verticalLayout_4">
    37. <item>
    38. <widget class="QTreeWidget" name="treeWidget">
    39. <column>
    40. <property name="text">
    41. <string>1</string>
    42. </property>
    43. </column>
    44. <column>
    45. <property name="text">
    46. <string>New Column</string>
    47. </property>
    48. </column>
    49. <column>
    50. <property name="text">
    51. <string>New Column</string>
    52. </property>
    53. </column>
    54. <column>
    55. <property name="text">
    56. <string>New Column</string>
    57. </property>
    58. </column>
    59. <column>
    60. <property name="text">
    61. <string>New Column</string>
    62. </property>
    63. </column>
    64. <item>
    65. <property name="text">
    66. <string>New Item</string>
    67. </property>
    68. </item>
    69. <item>
    70. <property name="text">
    71. <string>New Item</string>
    72. </property>
    73. </item>
    74. <item>
    75. <property name="text">
    76. <string>New Item</string>
    77. </property>
    78. </item>
    79. <item>
    80. <property name="text">
    81. <string>New Item</string>
    82. </property>
    83. </item>
    84. <item>
    85. <property name="text">
    86. <string>New Item</string>
    87. </property>
    88. </item>
    89. <item>
    90. <property name="text">
    91. <string>New Item</string>
    92. </property>
    93. <property name="text">
    94. <string>dfsdf</string>
    95. </property>
    96. <property name="text">
    97. <string>ssdddf</string>
    98. </property>
    99. </item>
    100. <item>
    101. <property name="text">
    102. <string>New Item</string>
    103. </property>
    104. </item>
    105. <item>
    106. <property name="text">
    107. <string>New Item</string>
    108. </property>
    109. </item>
    110. <item>
    111. <property name="text">
    112. <string>New Item</string>
    113. </property>
    114. </item>
    115. <item>
    116. <property name="text">
    117. <string>New Item</string>
    118. </property>
    119. </item>
    120. <item>
    121. <property name="text">
    122. <string>New Item</string>
    123. </property>
    124. </item>
    125. <item>
    126. <property name="text">
    127. <string>New Item</string>
    128. </property>
    129. </item>
    130. <item>
    131. <property name="text">
    132. <string>New Item</string>
    133. </property>
    134. </item>
    135. <item>
    136. <property name="text">
    137. <string>New Item</string>
    138. </property>
    139. </item>
    140. <item>
    141. <property name="text">
    142. <string>New Item</string>
    143. </property>
    144. </item>
    145. <item>
    146. <property name="text">
    147. <string>New Item</string>
    148. </property>
    149. </item>
    150. <item>
    151. <property name="text">
    152. <string>New Item</string>
    153. </property>
    154. </item>
    155. <item>
    156. <property name="text">
    157. <string>New Item</string>
    158. </property>
    159. </item>
    160. <item>
    161. <property name="text">
    162. <string>New Item</string>
    163. </property>
    164. </item>
    165. <item>
    166. <property name="text">
    167. <string>New Item</string>
    168. </property>
    169. </item>
    170. <item>
    171. <property name="text">
    172. <string>New Item</string>
    173. </property>
    174. </item>
    175. </widget>
    176. </item>
    177. </layout>
    178. </widget>
    179. </item>
    180. </layout>
    181. </widget>
    182. <widget class="QWidget" name="tab_2">
    183. <attribute name="title">
    184. <string>Tab 2</string>
    185. </attribute>
    186. </widget>
    187. </widget>
    188. </item>
    189. </layout>
    190. </widget>
    191. </widget>
    192. </item>
    193. </layout>
    194. </widget>
    195. <resources/>
    196. <connections/>
    197. </ui>
    To copy to clipboard, switch view to plain text mode 

    Here is the code:
    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3.  
    4. #include <QVBoxLayout>
    5. #include <QMdiArea>
    6. #include <QSplitter>
    7. #include <QScrollArea>
    8. #include <QTreeWidget>
    9.  
    10. MainWindow::MainWindow(QWidget *parent) :
    11. QMainWindow(parent),
    12. ui(new Ui::MainWindow)
    13. {
    14. ui->setupUi(this);
    15.  
    16. ui->centralWidget->setLayout(new QVBoxLayout);
    17. QMdiArea* mdi = new QMdiArea;
    18. mdi->setDocumentMode(true);
    19. ui->centralWidget->layout()->addWidget(mdi);
    20.  
    21. QTabWidget* tabWidget = new QTabWidget;
    22. mdi->addSubWindow(tabWidget);
    23. tabWidget->showMaximized();
    24.  
    25. QWidget* tab = new QWidget;
    26. tabWidget->addTab(tab, "Header");
    27.  
    28. QVBoxLayout* tabLayout = new QVBoxLayout;
    29. tab->setLayout(tabLayout);
    30.  
    31. QWidget* widget = new QWidget;
    32. tabLayout->addWidget(widget);
    33.  
    34. QVBoxLayout* widgetLayout = new QVBoxLayout;
    35. widget->setLayout(widgetLayout);
    36.  
    37. QTreeWidget* treeWidget = new QTreeWidget;
    38. treeWidget->setMinimumSize(200, 200);
    39. widgetLayout->addWidget(treeWidget);
    40.  
    41. // add some crap
    42. for(int i = 0; i != 20; ++i)
    43. (new QTreeWidgetItem(treeWidget))->setText(0, "Test " + QString::number(i));
    44. }
    45.  
    46. MainWindow::~MainWindow()
    47. {
    48. delete ui;
    49. }
    To copy to clipboard, switch view to plain text mode 
    "People who get offended should be offended" -- Linus Torvalds

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Resizing issues, minimum size is ignored by parent widgets

    Have you had a look at the generated code?
    Maybe you are not having exactly the same thing?

    Cheers,
    _

Similar Threads

  1. Replies: 6
    Last Post: 26th December 2015, 18:33
  2. Replies: 13
    Last Post: 16th October 2015, 11:42
  3. Resizing child widget on changing size of parent?
    By anupamgee in forum Qt Programming
    Replies: 3
    Last Post: 13th November 2009, 09:39
  4. resizing widgets depending on a main widget size
    By luf in forum Qt Programming
    Replies: 6
    Last Post: 10th October 2009, 17:13
  5. Replies: 2
    Last Post: 23rd March 2009, 18:26

Tags for this Thread

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.