Results 1 to 19 of 19

Thread: Layout issues, widgets get resized and unusable

  1. #1
    Join Date
    Apr 2015
    Posts
    28
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Layout issues, widgets get resized and unusable

    When a add a couple of widgets to a formLayout in a QDialog everything looks fine. But when I add a couple of widgets to a formLayout (in a QFrame) in a tab, they get resized in a weird way. Screenshot attached. Not sure what to google on this one.... need help!

    What I want is a large number of QLineEdit's, one below the other, and a scrollbar in the tab. What is a recommended approach on this? A QScrollArea instead of a QFrame?

    Screen_Shot_2015_04_20_at_19_32_01.png

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Layout issues, widgets get resized and unusable

    Hi,

    it looks, indeed, as if the frame has not enough space for the line edits. If you resize the tab widget, are the lineedits then shown normal? If so, it's a space problem.

    Quote Originally Posted by ecce View Post
    A QScrollArea instead of a QFrame?
    Yes, that's the way to go.

    Cheers.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Layout issues, widgets get resized and unusable

    The frame should push apart the encompassing dialog. If that doesn't happen then there is a layout missing somewhere. Possibly the frame itself is not in a layout.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Apr 2015
    Posts
    28
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Layout issues, widgets get resized and unusable

    If I make the tabs widget higher, the widgets does not get resized, but there are huge space between them. There seems to be a big "top and bottom margin" on them. This does not happen with the widgets in a QDialog.

    The frame itself is not in a layout, its added to the Tab Widget, which is in an layout.

    Screen_Shot_2015_04_20_at_21_06_46.png

  5. #5
    Join Date
    Apr 2013
    Location
    Prague
    Posts
    256
    Thanks
    3
    Thanked 65 Times in 59 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Layout issues, widgets get resized and unusable

    The layout "centers" its items vertically so that they use the available space. The layout items do not get any margins. As to the first picture: the items seem to have too small vertical size. Check in Designer and make the vertical size bigger.

  6. #6
    Join Date
    Apr 2015
    Posts
    28
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Layout issues, widgets get resized and unusable

    That does not seem to be exactly true, the widgets are at the top of the frame. There are a certain space between the widgets, and a lot of space after the last one (unless there are enough widgets to fill the vertical space). I don't have access to Qt Designer, I use the license free version.

  7. #7
    Join Date
    Apr 2013
    Location
    Prague
    Posts
    256
    Thanks
    3
    Thanked 65 Times in 59 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Layout issues, widgets get resized and unusable

    So do I (using Linux). Please, post your .ui (the bad one).

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Layout issues, widgets get resized and unusable

    Quote Originally Posted by ecce View Post
    The frame itself is not in a layout, its added to the Tab Widget, which is in an layout.
    Each tab in the tab widget can have a layout of its own. The frame should be put in a layout of the tab.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Apr 2015
    Posts
    28
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Layout issues, widgets get resized and unusable

    Quote Originally Posted by wysota View Post
    Each tab in the tab widget can have a layout of its own. The frame should be put in a layout of the tab.
    ... but QTabWidget.addTab() requires a widget and will fail if I supply a layout...?

    I've figured something out though, it seems to be the checkbox that messes things up a bit. If I remove it the space between the "rows" decreases.

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Layout issues, widgets get resized and unusable

    Quote Originally Posted by ecce View Post
    ... but QTabWidget.addTab() requires a widget and will fail if I supply a layout...?
    Are you passing QFrame instance to addTab? Does it change anything if you use QWidget instead?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #11
    Join Date
    Apr 2015
    Posts
    28
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Layout issues, widgets get resized and unusable

    Quote Originally Posted by wysota View Post
    Are you passing QFrame instance to addTab? Does it change anything if you use QWidget instead?
    Yes, I'm passing a QFrame to the addTab, and there does not seem to be any difference if I use a QWidget. I think I've worked around the space problem, not sure exactly why what I've done works better than before, but it does.

    The scrollable area however remains a problem. I've set the maximum height for the QTabWidget to 250, and I would like the contents of the tabs to be scrollable if they require more space than that. I've tried about a million ways, most of them looks something like this (although I use python). So far I've never seen a scrollbar.

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Layout issues, widgets get resized and unusable

    The important aspects of using the scroll area the way you want are:

    1. set widgetResizable to true
    2. make sure the widget has a layout or otherwise returns proper sizeHints.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  13. The following user says thank you to wysota for this useful post:

    ecce (21st April 2015)

  14. #13
    Join Date
    Apr 2015
    Posts
    28
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Layout issues, widgets get resized and unusable

    Quote Originally Posted by wysota View Post
    The important aspects of using the scroll area the way you want are:

    1. set widgetResizable to true
    2. make sure the widget has a layout or otherwise returns proper sizeHints.
    Thanks for the input, I've got a scrollbar, but it's not the finest GUI ever made to be honest: Screen_Shot_2015_04_21_at_20_52_14.png

    Here's the code:
    Qt Code:
    1. from PySide.QtGui import *
    2. from PySide.QtCore import *
    3.  
    4. class PolicyTabs(QTabWidget):
    5.  
    6. # Constructor
    7. def __init__(self):
    8. QTabWidget.__init__(self)
    9. self.setMaximumHeight(250)
    10.  
    11. t = testWidget()
    12.  
    13. self.addTab(t, "Model and IOS")
    14.  
    15. class testWidget(QWidget):
    16.  
    17. def __init__(self, parent= None):
    18. super(testWidget, self).__init__()
    19.  
    20. w = QWidget()
    21. vbox = QVBoxLayout(self)
    22.  
    23. t1 = policyItem("Test1:")
    24. t2 = policyItem("Test2:")
    25. t3 = policyItem("Test3:")
    26. t4 = policyItem("Test4:")
    27. t5 = policyItem("Test5:")
    28. t6 = policyItem("Test6:")
    29. vbox.addLayout(t1)
    30. vbox.addLayout(t2)
    31. vbox.addLayout(t3)
    32. vbox.addLayout(t4)
    33. vbox.addLayout(t5)
    34. vbox.addLayout(t6)
    35.  
    36. w.setLayout(vbox)
    37.  
    38. #Scroll Area Properties
    39. scroll = QScrollArea()
    40. scroll.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
    41. scroll.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
    42. scroll.setWidgetResizable(True)
    43. scroll.setWidget(w)
    44.  
    45. #Scroll Area Layer add
    46. vLayout = QVBoxLayout(self)
    47. vLayout.addWidget(scroll)
    48. self.setLayout(vLayout)
    49.  
    50.  
    51.  
    52. class policyItem(QHBoxLayout):
    53.  
    54. text = ''
    55.  
    56. def __init__(self, label):
    57. QHBoxLayout.__init__(self)
    58.  
    59. self.c = QCheckBox()
    60. self.l = QLabel(label)
    61. self.t = QLineEdit()
    62.  
    63. self.t.textChanged.connect(self.saveText)
    64.  
    65. self.addWidget(self.c)
    66. self.addWidget(self.l)
    67. self.addWidget(self.t)
    68.  
    69.  
    70. def getText(self):
    71. return self.t.text()
    72.  
    73. def isChecked(self):
    74. return self.c.isChecked()
    75.  
    76. def saveText(self):
    77. self.text = self.t.text()
    78. #print self.text
    To copy to clipboard, switch view to plain text mode 

    Why the big margins between the scrollable area an the boundaries of the tab?

  15. #14
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Layout issues, widgets get resized and unusable

    Why not simply have a grid with two columns, first one with checkbox (giving you also the label) and the second with a line edit?

    As for the boundaries, they come from margins of the scroll area and the empty (and definitely not needed) widget. Put the scroll area directly into the tab widget instead and the margin should go away.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  16. #15
    Join Date
    Apr 2015
    Posts
    28
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Layout issues, widgets get resized and unusable

    Quote Originally Posted by wysota View Post
    Why not simply have a grid with two columns, first one with checkbox (giving you also the label) and the second with a line edit?

    As for the boundaries, they come from margins of the scroll area and the empty (and definitely not needed) widget. Put the scroll area directly into the tab widget instead and the margin should go away.
    Sounds good. Can't get it to work though. Am I doing anything wrong by thinking like this?

    1. Create a QGridLayout
    2. Add widgets
    3. Create a QScrollArea
    4. Set scroll properties
    5. You must set a widget in the ScrollArea. The GridLayout is not a widget, so...
    6. Create an empty QWidget
    7. Set the QWidget as the layout parent
    8. Now you can set the widget with the QScrollArea function

    The result is just what I had before, the widgets gets resized. Code:

    Qt Code:
    1. from PySide.QtGui import *
    2. from PySide.QtCore import *
    3.  
    4. class PolicyTabs(QTabWidget):
    5.  
    6. # Constructor
    7. def __init__(self):
    8. QTabWidget.__init__(self)
    9. self.setMaximumHeight(250)
    10.  
    11. #t = testWidget()
    12.  
    13. w = QWidget()
    14.  
    15. layout = QGridLayout(w)
    16. c1 = QCheckBox("Label")
    17. t1 = QLineEdit()
    18. c2 = QCheckBox("Label")
    19. t2 = QLineEdit()
    20. c3 = QCheckBox("Label")
    21. t3 = QLineEdit()
    22. c4 = QCheckBox("Label")
    23. t4 = QLineEdit()
    24. c5 = QCheckBox("Label")
    25. t5 = QLineEdit()
    26. c6 = QCheckBox("Label")
    27. t6 = QLineEdit()
    28. c7 = QCheckBox("Label")
    29. t7 = QLineEdit()
    30. layout.addWidget(c1, 0, 0)
    31. layout.addWidget(t1, 0, 1)
    32. layout.addWidget(c2, 1, 0)
    33. layout.addWidget(t2, 1, 1)
    34. layout.addWidget(c3, 2, 0)
    35. layout.addWidget(t3, 2, 1)
    36. layout.addWidget(c4, 3, 0)
    37. layout.addWidget(t4, 3, 1)
    38. layout.addWidget(c5, 4, 0)
    39. layout.addWidget(t5, 4, 1)
    40. layout.addWidget(c6, 5, 0)
    41. layout.addWidget(t6, 5, 1)
    42. layout.addWidget(c7, 6, 0)
    43. layout.addWidget(t7, 6, 1)
    44.  
    45. scroll = QScrollArea()
    46. scroll.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
    47. scroll.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
    48. scroll.setWidgetResizable(True)
    49. scroll.setWidget(w)
    50.  
    51. self.addTab(w, "Model and IOS")
    To copy to clipboard, switch view to plain text mode 

  17. #16
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Layout issues, widgets get resized and unusable

    I meant something like the attached form.
    Attached Files Attached Files
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  18. #17
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,968
    Thanks
    277
    Thanked 808 Times in 797 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Layout issues, widgets get resized and unusable

    I meant something like the attached form.
    If you insert a vertical spacer under the last checkbox, I think it makes the behaviour more pleasing - the spacing between the rows stays constant, no matter what size the form is. That's my personal preference, of course, but I find that the alternative - having the child widgets spread out when the form is enlarged - not so visually pleasing, especially in a tab widget context. Depending on how many child widgets are in each tab, the spacings can vary widely as you go from tab to tab. If you use spacers, then each tab will have some layout consistency with the others in the group.

  19. #18
    Join Date
    Apr 2015
    Posts
    28
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Layout issues, widgets get resized and unusable

    Quote Originally Posted by wysota View Post
    I meant something like the attached form.
    Got it working! Thanks a bunch! (Sorry for the delayed answer, girlfriend just gave birth to twin boys, been away for a while...)

  20. #19
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Layout issues, widgets get resized and unusable

    Quote Originally Posted by ecce View Post
    (Sorry for the delayed answer, girlfriend just gave birth to twin boys, been away for a while...)
    Congratulations
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 0
    Last Post: 30th April 2012, 15:17
  2. Replies: 5
    Last Post: 18th April 2010, 23:31
  3. Replies: 5
    Last Post: 18th March 2010, 09:54
  4. Layout issues
    By vijay anandh in forum Qt Programming
    Replies: 2
    Last Post: 8th July 2006, 19:27

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.