2

I would like to able to drag the first or second splitters in the code below to the right and have the widget inside the scroll area push out to the right when the width limit of each widget is reached (like when the window is resized smaller and the widget inside the scroll area is progressively hidden). Currently if I drag a splitter to the right, the scrolling stops when the width limit of the widgets is reached. Any idea how to do this.

import sys
from PyQt4 import QtGui, QtCore
from PyQt4.QtGui import QScrollArea

class Example(QtGui.QWidget):

    def __init__(self):
        super(Example, self).__init__()
        self.initUI()

    def initUI(self):      
        hbox = QtGui.QHBoxLayout(self)
        first = QtGui.QFrame(self)
        first.setFrameShape(QtGui.QFrame.StyledPanel)
        first.setMinimumWidth(50)
        second = QtGui.QFrame(self)
        second.setFrameShape(QtGui.QFrame.StyledPanel)
        second.setMinimumWidth(50)
        third = QtGui.QFrame(self)
        third.setFrameShape(QtGui.QFrame.StyledPanel)
        third.setMinimumWidth(50)
        splitter = QtGui.QSplitter(QtCore.Qt.Horizontal)
        splitter.addWidget(first)
        splitter.addWidget(second)
        splitter.addWidget(third)
        scrollArea = QScrollArea()  
        scrollArea.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
        scrollArea.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
        scrollArea.setWidgetResizable(True)
        scrollArea.setWidget(splitter)
        hbox.addWidget(scrollArea)
        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()  
Don Smythe
  • 9,234
  • 14
  • 62
  • 105
  • I run your sample. When I drag the right slider to the right, the right area decrease its width. Then it stop decreasing and if continue to drag to the right, the right area is pushed out. Is it the right behavior? Maybe you can rephrase the current and desired behaviors in your question. – Ortomala Lokni Mar 04 '15 at 14:34
  • @Ortimala Lokni Thanks for looking into this. I tried on both Windows and Linux. When I drag the rightmost splitter to the right it hits the 50 pixel limit, then jumps to the right window border and stops, the scroll area is not pushed out. On Win I'm using python 2 + Qt that comes bundled with a recent Anaconda download. On Linux I'm using python 3+ PyQt4.11.3 – Don Smythe Mar 05 '15 at 13:08
  • 1
    I have the same problem. I can't force the scroll area larger by moving a splitter. – Rafe Apr 13 '17 at 21:52

0 Answers0