I have two widgets residing one next to each other, WidgetA and WidgetB, on a QDialog, with a horizontal Layout Manager.
I am trying to enforce the following size/resize policies:
For WidgetA:
- Horizontally: Width should be 900 with the ability to shrink (up to 100), and to expand (to whatever).
- Vertically: Height should be 600 with the ability to expand (to whatever).
For WidgetB:
- Horizontally: Width should be Fixed to 600.
- Vertically: Height should be 600, with the ability to expand (to whatever) - same as
WidgetA.
But no matter which size policy I choose for WidgetA, it still won't take up width of 900.
Here's a code sample:
class WidgetA(QTextEdit):
def __init__(self, parent = None):
super(WidgetA, self).__init__(parent)
#self.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.MinimumExpanding) --> WidgetA width still smaller than 900
#self.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.MinimumExpanding) --> WidgetA will be set to minimumSizeHint()
#self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.MinimumExpanding) --> not good for me, since I want WidgetA to be able to shrink up to minimumSizeHint().width()
#self.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.MinimumExpanding) --> not good for me for the same reason - I want WidgetA to be able to shrink up to minimumSizeHint().width()
def minimumSizeHint(self):
return QSize(100, 600)
def sizeHint(self):
return QSize(900, 600)
class WidgetB(QTextEdit):
def __init__(self, parent = None):
super(WidgetB, self).__init__(parent)
self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.MinimumExpanding)
def sizeHint(self):
return QSize(600, 600)
class MainForm(QDialog):
def __init__(self, parent = None):
super(MainForm, self).__init__(parent)
label_a = QLabel('A')
widget_a = WidgetA()
label_a.setBuddy(widget_a)
label_b = QLabel('B')
widget_b = WidgetB()
label_b.setBuddy(widget_b)
hbox = QHBoxLayout()
vbox = QVBoxLayout()
vbox.addWidget(label_a)
vbox.addWidget(widget_a)
widget = QWidget()
widget.setLayout(vbox)
hbox.addWidget(widget)
vbox = QVBoxLayout()
vbox.addWidget(label_b)
vbox.addWidget(widget_b)
widget = QWidget()
widget.setLayout(vbox)
hbox.addWidget(widget)
self.setLayout(hbox)
def run_app():
app = QApplication(sys.argv)
form = MainForm()
form.show()
app.exec_()
if __name__ == '__main__':
run_app()
The closest I could get is when I set:
self.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.MinimumExpanding)
On WidgetA.
It seems like WidgetB is taking a bite off of WidgetA's 900 width (eliminating WidgetB does the trick), but I shouldn't be limited by the window's width.
What's preventing from the window itself (the MainForm) to automatically expand horizontally in order to account for both WidgetA's 900 width and WidgetB's fixed 600 width?
