[PyQt] Toolbar widget sizing problems

Scott Price scottmprice at gmail.com
Fri Sep 5 19:47:31 BST 2008


Hi there,

I'm running WindowsXP.

So using PyQt4x I set up a toolbar, add a line edit to it, set the geometry
and sizepolicy of the line-edit widget, and watch as the toolbar promptly
ignores any directions I give the child widget!  

Is there a secret to making the toolbar respect the size policies and
geometry that is set on its child widgets?  I suspect (not sure about this)
that in the process of re-parenting the child widget when adding to the
toolbar those are being reset to some default, but the documentation neither
explains this nor hints at it.  

Sample code:

        vMax = QtGui.QSizePolicy()
        vMax.setVerticalPolicy(QtGui.QSizePolicy.Minimum)
        vMax.setHorizontalPolicy(QtGui.QSizePolicy.Minimum)

        goGroup = QtGui.QGroupBox()
        goGroup.setGeometry(QtCore.QRect(0,0,350,30))
        goGroup.setFlat(True)
        goGroup.setTitle(self.tr("Go To:"))

        layout = QtGui.QHBoxLayout()
        
        goTo = QtGui.QLineEdit()
        layout.addWidget(goTo)
        
        goGroup.setLayout(layout)
        
        self.toolBar = QtGui.QToolBar(self)
        self.addToolBar(self.toolBar)
        self.toolBar.addWidget(goGroup)
        
        goTo.setGeometry(QtCore.QRect(0,0,350,30))
        goTo.setSizePolicy(vMax)
        
This code results in a line-edit of about 100x20 pixels.  It doesn't appear
to make any difference what order I attempt to set the various
geometries/size policies in.  Setting them on the group box, layout, line
edit, and toolbar in any combination or order has no effect.

There's got to be something obvious that I'm missing, but I can't spot it!
Ideas?

Thanks,
Scott



More information about the PyQt mailing list