KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have a QLabel and a QLineEdit inside a QWidget. When I have the widget inside a QScrollArea, the line edit does not expand to occupy the excess width of the window. When the widget is not inside the scroll area, it does expand. I've tried setting the size policy of the line edit and the widget, to expand horizontally, but it doesn't occupy the excess space. I suspect the sizeHint() of the widget is compacted when inside a scroll area. Any ideas how to make this work? class MainWindow(QtGui.QMainWindow): def __init__(self): QtGui.QMainWindow.__init__(self, None) self.setWindowTitle('Test Window') self.resize(500, 250) scrollArea = QtGui.QScrollArea() scrollWidget = QtGui.QWidget() scrollWidget.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Maximum) layout = QtGui.QGridLayout(scrollWidget) label = QtGui.QLabel("Name:") layout.addWidget(label, 0, 0) lineEdit = QtGui.QLineEdit("Value") lineEdit.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Maximum) layout.addWidget(lineEdit, 0, 1) scrollWidget.setLayout(layout) scrollArea.setWidget(scrollWidget) self.setCentralWidget(scrollArea)
Tags (comma-separated)
Save Edits
Cancel