QStackedWidget layout problem
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??
Re: QStackedWidget layout problem
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
Re: QStackedWidget layout problem
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).
1 Attachment(s)
Re: QStackedWidget layout problem
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
Re: QStackedWidget layout problem
I don't see the effect you experience. For me the stacked widget remains the same regardless of which page is currently being displayed.
Re: QStackedWidget layout problem
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
Re: QStackedWidget layout problem
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
Re: QStackedWidget layout problem
Hello again
I found my problem - I was not setting currentIndex of the stackwidget for each page. Works a treat now !
Re: QStackedWidget layout problem
"self.pgSurvey.show()" - this is wrong. Let the stacked widget control the visibility of its widgets.
Re: QStackedWidget layout problem
Yes thanks Wysota - I discovered that after rereading the documentation!!