You need to use the setStretchFactor
method on your QSplitter
.
An example (modified from the QSplitter example here):
import sys
from PyQt4 import QtGui, QtCore
class Example(QtGui.QWidget):
def __init__(self):
super(Example, self).__init__()
self.initUI()
def initUI(self):
hbox = QtGui.QHBoxLayout(self)
left = QtGui.QFrame(self)
left.setFrameShape(QtGui.QFrame.StyledPanel)
right = QtGui.QFrame(self)
right.setFrameShape(QtGui.QFrame.StyledPanel)
splitter = QtGui.QSplitter(QtCore.Qt.Horizontal)
splitter.addWidget(left)
splitter.addWidget(right)
splitter.setStretchFactor(1, 1)
splitter.setSizes([125, 150])
hbox.addWidget(splitter)
self.setLayout(hbox)
QtGui.QApplication.setStyle(QtGui.QStyleFactory.create('Cleanlooks'))
self.setGeometry(300, 300, 300, 200)
self.setWindowTitle('QtGui.QSplitter')
self.show()
def main():
app = QtGui.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
This produces an initial UI that looks like this:
![Initial UI](https://cdn.statically.io/img/i.sstatic.net/PGtRf.png)
When the image is expanded horizontally, you can see that the left widget stays the same size:
![Expanded horizontally](https://cdn.statically.io/img/i.sstatic.net/B6e0M.png)
When expanded vertically, both widgets expand:
![enter image description here](https://cdn.statically.io/img/i.sstatic.net/rqtXq.png)
Finally, the splitter is resizeable:
![Resizeable](https://cdn.statically.io/img/i.sstatic.net/Aom25.png)
If you adjust the window size after adjusting the splitter, the left widget will retain it's size and the right will expand/collapse to fill the remainder of the window.