PyQt将QSplitter调整为大于QScrollArea

时间:2015-02-28 04:21:06

标签: python qt pyqt pyqt4

我希望能够将下面代码中的第一个或第二个分割器向右拖动,并在达到每个小部件的宽度限制时将滚动区域内的小部件向右推出(就像窗口是调整大小,滚动区域内的小部件逐渐隐藏)。目前,如果我将分割器向右拖动,则在达到小部件的宽度限制时滚动停止。不知道怎么做。

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()  

0 个答案:

没有答案