PDA

View Full Version : QStackedWidget layout problem



Banjo
6th May 2008, 00:22
Hello
I have a QStackedWidget with four pages all of which have layouts. I have created this using Designer.

What I am finding though is that when the application is run, the stacked widget takes on the dimensions of whatever page was current when the ui file was created. Ideally I would like all the pages to be the same size. They look the same size in designer, just not when the application is run.

Any help with this??

Banjo
12th May 2008, 01:45
Hello
Is anyone able to help me - I seem to remember a post on this problem before but have been unable to find it.
Thanks

wysota
12th May 2008, 07:52
What you describe is not a natural behaviour - the stacked widget should have the size of the largest of its widgets and all the other widgets should adjust to it. If you observe a different behaviour, it might mean you forgot to apply a layout somewhere (for instance in the parent of the stacked widget).

Banjo
13th May 2008, 00:39
Hello
Thanks for that. I have looked for missing layouts but can't see any. I've attached a copy of the ui file and would appreciate it if you would have a look.

I am using Designer to contruct the basic interface.

Thanks

wysota
13th May 2008, 06:58
I don't see the effect you experience. For me the stacked widget remains the same regardless of which page is currently being displayed.

Banjo
13th May 2008, 08:09
Thanks for looking at it - must be a problem with my Python code.

Given that I am stumped on this, can you give me any general pointers as to how to find the offending bit. I do not specify/delete layouts in my Python code. I am adding dock widgets top, right and bottom.

Thanks again

Banjo
14th May 2008, 01:09
I have explored a little further and found the following:

1) The pages all size correctly in Designer

2) I have cut my Python code right down and the same problem still occurs when the application is run - ie the only page that shows correctly is the page that was current when saving the ui file (and then using pyuic4 to create the python file).

Here is my cut down code.

class MainWindow(QMainWindow, Ui_MainWindow):
def __init__(self, parent=None):
super(MainWindow,self).__init__(parent)

self.setupUi(self)
self.pgSurvey.show() # non current page in stacked widget


def main():
app = QApplication(sys.argv)
mainWindow = MainWindow()
mainWindow.show()
sys.exit(app.exec_())

main()

so I am assuming that the ui file is correct as Wysota says.

Any suggestions as I am stumped on this.

Thanks

Banjo
14th May 2008, 02:18
Hello again

I found my problem - I was not setting currentIndex of the stackwidget for each page. Works a treat now !

wysota
14th May 2008, 07:15
"self.pgSurvey.show()" - this is wrong. Let the stacked widget control the visibility of its widgets.

Banjo
15th May 2008, 00:15
Yes thanks Wysota - I discovered that after rereading the documentation!!