Results 1 to 2 of 2

Thread: QDockWidget not restored with restoreState/saveState

  1. #1
    Join Date
    Oct 2010
    Posts
    95
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Question QDockWidget not restored with restoreState/saveState

    Hi,

    I use QT 5.0.2 and have a main window that contains several QDockWidgets.
    Once the application close, I call

    Qt Code:
    1. settings.setValue("windowState", saveState());
    2. settings.setValue("geometry", geometry());
    To copy to clipboard, switch view to plain text mode 

    And once I open it I call :

    Qt Code:
    1. restoreState(settings.value("windowState").toByteArray());
    2. restoreGeometry(settings.value("geometry").toByteArray());
    To copy to clipboard, switch view to plain text mode 

    But my dock widgets "size" is not correctly restored !

    So, does someone has an idea of the problem ? and how to solve it ?

    Thanks

    BTW : I have take a look on google for a work around... and play with several "possible solution", but no way :-(

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: QDockWidget not restored with restoreState/saveState

    I think your problem is with multiple QDockWidgets, from your example it is evedent that it will not work as all the QDockWidget save and restore the settings with same key value, you will need to differentiate them, somting like
    Qt Code:
    1. settings.setValue("windowState1", windowState1.saveState());
    2. settings.setValue("geometry1", geometry1.geometry());
    3.  
    4. settings.setValue("windowState2", windowState2.saveState());
    5. settings.setValue("geometry2", geometry2.geometry());
    6.  
    7. settings.setValue("windowState3", windowState3.saveState());
    8. settings.setValue("geometry3", geometry3.geometry());
    To copy to clipboard, switch view to plain text mode 

    or use QSetting arrays.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

Similar Threads

  1. Floating QDockWidget not re-docked by QMainWindow::restoreState
    By stefanadelbert in forum Qt Programming
    Replies: 14
    Last Post: 20th October 2016, 21:16
  2. QDockWidget saveState and restoreState
    By ^NyAw^ in forum Qt Programming
    Replies: 3
    Last Post: 28th January 2016, 09:56
  3. Replies: 0
    Last Post: 8th November 2012, 17:09
  4. Why a restored window doesn't keep it's state (sizes)?
    By evgeniy in forum Qt Programming
    Replies: 0
    Last Post: 3rd December 2011, 07:47
  5. MDI child looses focus when app is restored
    By John_P in forum Qt Programming
    Replies: 2
    Last Post: 2nd October 2007, 10:34

Tags for this Thread

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.