Results 1 to 10 of 10

Thread: QStackedWidget layout problem

  1. #1
    Join Date
    Jan 2008
    Posts
    39
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default 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??

  2. #2
    Join Date
    Jan 2008
    Posts
    39
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default 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

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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).

  4. #4
    Join Date
    Jan 2008
    Posts
    39
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default 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
    Attached Files Attached Files

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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.

  6. #6
    Join Date
    Jan 2008
    Posts
    39
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default 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

  7. #7
    Join Date
    Jan 2008
    Posts
    39
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy 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

  8. #8
    Join Date
    Jan 2008
    Posts
    39
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default 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 !

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QStackedWidget layout problem

    "self.pgSurvey.show()" - this is wrong. Let the stacked widget control the visibility of its widgets.

  10. The following user says thank you to wysota for this useful post:

    Banjo (15th May 2008)

  11. #10
    Join Date
    Jan 2008
    Posts
    39
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QStackedWidget layout problem

    Yes thanks Wysota - I discovered that after rereading the documentation!!

Similar Threads

  1. Layout Problem
    By sabonis in forum Qt Tools
    Replies: 4
    Last Post: 3rd March 2008, 20:57
  2. problem with Tool button n Layout
    By arjunasd in forum Qt Tools
    Replies: 11
    Last Post: 24th July 2007, 21:14
  3. QStackedWidget fill Postscript image And scroll problem
    By patrik08 in forum Qt Programming
    Replies: 11
    Last Post: 22nd April 2007, 09:30
  4. Grid Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2006, 12:45
  5. Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 4
    Last Post: 19th April 2006, 11:08

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.