Hi,

I'm trying to lay out some QScrollAreas using QGridLayout with Qt 4.2 for
Windows but I'm getting unexpected results.

I have a 2x2 grid, with the following widgets:
- A QScrollArea named "ea" at row 1, column 1
- A QScrollArea named "ca" at row 0, column 1
- A QScrollArea named "ta" at row 1, column 0

The idea is that the width of column 0 and the height of row 0 should be
fixed, with row 1 and column 1 expanding to take all the remaining space.

However, when I try to achieve this, I get the following geometries for the
widgets:

ea:  x = 62, y = 62, width = 138, height = 88
ca: x = 62, y = 21, width = 138, height = 20
ta: x = 0, y = 62, width = 20, height = 88

Note that ca's height and ta's width is 20, as I expected, but for some
reason column 0 and row 0 both seem to take 62 pixels, instead of the
expected 20.  Also, again for unexplained reasons, row 0 is centered in the
62 pixel gap, while column 0 is on the left of its gap.

The code for my test case is this:


import sys
from PyQt4 import QtCore, QtGui

app = QtGui.QApplication(sys.argv)
mw = QtGui.QMainWindow()

cw = QtGui.QWidget(mw)

gl = QtGui.QGridLayout(cw)
gl.setMargin(0)
gl.setSpacing(0)

ea = QtGui.QScrollArea(cw)

sp = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding,
QtGui.QSizePolicy.Expanding)
sp.setHorizontalStretch(1)
sp.setVerticalStretch(1)
ea.setSizePolicy(sp)

e = QtGui.QWidget(ea)
ea.setWidget(e)
ea.setWidgetResizable(True)

gl.addWidget(ea, 1, 1)

ca = QtGui.QScrollArea(cw)

sp = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Fixed)
sp.setHorizontalStretch(1)
sp.setVerticalStretch(0)
ca.viewport().setSizePolicy(sp)
ca.setSizePolicy(sp)

c = QtGui.QWidget(ca)
ca.setWidget(c)
ca.setWidgetResizable(True)
ca.setMinimumSize(0, 20)

gl.addWidget(ca, 0, 1)

ta = QtGui.QScrollArea(cw)

sp = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Expanding)
sp.setHorizontalStretch(0)
sp.setVerticalStretch(1)
ta.viewport().setSizePolicy(sp)
ta.setSizePolicy(sp)

t = QtGui.QWidget(ta)
ta.setWidget(t)
ta.setWidgetResizable(True)
ta.setMinimumSize(20, 0)

gl.addWidget(ta, 1, 0)

gl.setColumnStretch(0, 0)
gl.setRowStretch(0, 0)
gl.setColumnStretch(1, 1)
gl.setRowStretch(1, 1)
gl.update()

mw.setCentralWidget(cw)

mw.show()

for w in (ea, ca, ta):
   g = w.geometry()
   print "x=%d y=%d w=%d h=%d" % (g.x(), g.y(), g.width(), g.height())

app.exec_()


I have also attached a screenshot of the result.

Please also note that if I replace the QScrollAreas with QFrames it does
seem to work as expected.

I'm really at my wits' end, so any help would be greatly appreciated.

--
Miguel

Attachment: qgridlayout-screenshot.png
Description: PNG image

_______________________________________________
PyKDE mailing list    [email protected]
http://mats.imk.fraunhofer.de/mailman/listinfo/pykde

Reply via email to