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.
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.
ecce (21st April 2015)
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:
from PySide.QtGui import * from PySide.QtCore import * # Constructor def __init__(self): self.setMaximumHeight(250) t = testWidget() self.addTab(t, "Model and IOS") def __init__(self, parent= None): super(testWidget, self).__init__() t1 = policyItem("Test1:") t2 = policyItem("Test2:") t3 = policyItem("Test3:") t4 = policyItem("Test4:") t5 = policyItem("Test5:") t6 = policyItem("Test6:") vbox.addLayout(t1) vbox.addLayout(t2) vbox.addLayout(t3) vbox.addLayout(t4) vbox.addLayout(t5) vbox.addLayout(t6) w.setLayout(vbox) #Scroll Area Properties scroll.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn) scroll.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) scroll.setWidgetResizable(True) scroll.setWidget(w) #Scroll Area Layer add vLayout.addWidget(scroll) self.setLayout(vLayout) text = '' def __init__(self, label): self.t.textChanged.connect(self.saveText) self.addWidget(self.c) self.addWidget(self.l) self.addWidget(self.t) def getText(self): return self.t.text() def isChecked(self): return self.c.isChecked() def saveText(self): self.text = self.t.text() #print self.textTo copy to clipboard, switch view to plain text mode
Why the big margins between the scrollable area an the boundaries of the tab?
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:
from PySide.QtGui import * from PySide.QtCore import * # Constructor def __init__(self): self.setMaximumHeight(250) #t = testWidget() layout.addWidget(c1, 0, 0) layout.addWidget(t1, 0, 1) layout.addWidget(c2, 1, 0) layout.addWidget(t2, 1, 1) layout.addWidget(c3, 2, 0) layout.addWidget(t3, 2, 1) layout.addWidget(c4, 3, 0) layout.addWidget(t4, 3, 1) layout.addWidget(c5, 4, 0) layout.addWidget(t5, 4, 1) layout.addWidget(c6, 5, 0) layout.addWidget(t6, 5, 1) layout.addWidget(c7, 6, 0) layout.addWidget(t7, 6, 1) scroll.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn) scroll.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) scroll.setWidgetResizable(True) scroll.setWidget(w) self.addTab(w, "Model and IOS")To copy to clipboard, switch view to plain text mode
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.I meant something like the attached form.
Bookmarks