View Full Version : Sizing Issues

13th February 2006, 17:44
I'm continually running into the problem of my child widgets appearing all scrunched together in a little box instead of taking up what I would imagine is the actual screen space. I'm not sure why such small size parameter are being passed down. I don't want to set minimum/maximum sizes as this needs to be adapted to different screens.

My immediate problem is setting a splitterinside a tab. It takes up maybe a quarter of the width. The children of the splitter are thus in a small space instead of taking up the whole tab. I think there is something fundamental to Qt I am missing here. If someone could give me a hint with how to procede it would be greatly appreciated.

I'm using PyQt but its all the similar, here is how I'm specifying the splitter size:
splitter.setGeometry(QRect(0, 25, self.frameSize().width(), self.frameSize().height()))

13th February 2006, 17:56
Yes, you are missing something :) This something is called "layouts" :) Take a look at the QLayout class and its descendants, Johan's tutorial and official Qt tutorial for details.

13th February 2006, 18:03
I'm familiar wtih layouts. If I'm using a splitter though is it necessary for me to put it in a layout as it will be the only item directly inside the tab. I'm using layouts to organize all the child widgets of the splitter though.

class DrugProfile(QWidget):
def __init__(self, parent):
QWidget.__init__(self, parent)
splitter = QSplitter(Qt.Vertical, self, "header")
splitter.setGeometry(QRect(0, 25, self.frameSize().width(), self.frameSize().height()))
head = Header(splitter) #top child
table = Tables(splitter) #bottom child

13th February 2006, 18:05
Maybe you should use sizeHint() instead of frameSize()? Widget sizes aren't valid until the widget is shown for the first time.

13th February 2006, 18:14
It came back with the same results.

When I comment out the code of the children it gets even smaller. So the size of the splitter is being determined by its child classes, its widest childset. I think I'll have to investigate that further. I'll have to figure out how to get the children to take up the whole space.

13th February 2006, 19:10
You should put that splitter into a layout too. And the parent should not be a QWidget. Or you can derive your class directly from QSplitter (it'll be even better this way).

Something like:

class DrugProfile(QSplitter):
def __init__(self, parent):
QSplitter.__init__(Qt.Vertical, self, parent)
head = Header(self) #top child
table = Tables(self) #bottom child

13th February 2006, 19:14
Ok I'll give that a try too. I have a vague memory of having done that but it really makes more sense anyway.

13th February 2006, 19:17
It worked! Thanks!! I'll post if I have another related question but this looks like I am majorly closer to what I want. Its always a simple solution :) .