Results 1 to 19 of 19

Thread: Layout issues, widgets get resized and unusable

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 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.


  2. #2
    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.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 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.


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

    ecce (21st April 2015)

  5. #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

    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?

  6. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 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.


  7. #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

    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 

  8. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 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.


  9. #8
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,319
    Thanks
    316
    Thanked 870 Times in 857 Posts
    Qt products
    Qt5
    Platforms
    Windows

    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.

  10. #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
    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...)

  11. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 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
  •  
Qt is a trademark of The Qt Company.