pyqt - QSplitter question

Jim jbublitzNO at SPAMnwinternet.com
Fri Feb 7 02:05:57 EST 2003


Vio wrote:
> I want to make a vertical QSplitter use 25% of available space for the 
> left pane, and 75% for the right pane (your classic 'nav tree' on left 
> pane and 'edit' widget in right pane).

> My current code only allows 50-50 splits:

> ...
> self.setCentralWidget(QWidget(self,"qt_central_widget"))
> self.layout_central_splitter = 
> QHBoxLayout(self.centralWidget(),0,-1,"layout_central_splitter")
> # CENTRAL SPLITTER
> self.splitter1 = QSplitter(self.centralWidget(),"splitter1")
> self.splitter1.setOrientation(QSplitter.Horizontal)
> self.layout_central_splitter.addWidget(self.splitter1)# add Widget to 
> Layout Manager
> ...

> Adding something like:

> self.splitter1.setSizePolicy(QSizePolicy(7,7,0,0,self.splitter1.sizePolicy().hasHeightForWidth())) 

> seems to have no apparent effect.

For a single splitter (not in a QLayout):

splitter = QSplitter (parent)
splitter.setGeometry (...)
<add left and right widgets>
w = QSplitter.width () - margins # not sure if the 'margin'
                                  # adjustment is needed
splitter.setSizes ([w/4, 3*w/4])

setSizes is a QSplitter method and takes a Python list
of int under PyQt. Otherwise, see the Qt docs.

That will allow you to move the splitter divider anywhere.
If you want to restrict or fix the size of one side, use
setMaximumWidth/setMinimumWidth or setFixedWidth on the
*widget* (not the QSplitter) you want to constrain.


Jim





More information about the Python-list mailing list