Results 1 to 3 of 3

Thread: QSplitter::restoreState() not working

  1. #1
    Join Date
    Oct 2010
    Posts
    5
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default QSplitter::restoreState() not working

    Hey all!

    I have a quick question: When using a splitter, I would like it to restore itself to the position it was at last time the application closed. I have been able to restore the main window's geometry just fine, but when attempting to restore a splitter, it doesn't work.

    When the application starts:
    Qt Code:
    1. QSettings settings;
    2.  
    3. // Main window settings
    4. settings.beginGroup("mainWindow");
    5. restoreGeometry(settings.value("geometry").toByteArray());
    6. splitter->restoreState(settings.value("splitterState").toByteArray());
    7. settings.endGroup();
    To copy to clipboard, switch view to plain text mode 

    When a close event is called:
    Qt Code:
    1. QSettings settings;
    2.  
    3. // Main window settings
    4. settings.beginGroup("mainWindow");
    5. settings.setValue("geometry", saveGeometry());
    6. settings.setValue("splitterState", splitter->saveState());
    7. settings.endGroup();
    To copy to clipboard, switch view to plain text mode 

    The splitter always starts in the middle, regardless of where I leave it at close.

    Any help?

  2. #2
    Join Date
    May 2010
    Posts
    61
    Thanks
    2
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QSplitter::restoreState() not working

    Hi PeterThePuter,

    I also tested this and noticed that you can correctly save into QSettings object only if you define the organizationName on the QApplication object.
    Something like this:
    Qt Code:
    1. QApplication a(argc, argv);
    2. a.setOrganizationName("TestSplitter");
    To copy to clipboard, switch view to plain text mode 
    Last edited by wladek; 25th October 2010 at 12:29.
    One second is long, everything longer than two seconds is definitely too long.

  3. #3
    Join Date
    Dec 2011
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QSplitter::restoreState() not working

    Hello,

    I have exactly the same issue. The issue is not in saving the
    QSplitter state. I am sure that the data is well stored and read
    from my settings file.

    The issue is that, in some case, the QSplitter is not restored.

    PeterThePuter, did you solve that issue?

    Thanks

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. QMainWindow : restorestate problems
    By fmariusd in forum Qt Programming
    Replies: 10
    Last Post: 30th October 2009, 08:05
  4. QSplitter
    By weixj2003ld in forum Qt Programming
    Replies: 1
    Last Post: 8th April 2009, 13:46
  5. QMainWindow::restoreState
    By EnErGy[CSDX] in forum Qt Programming
    Replies: 3
    Last Post: 15th September 2008, 00:49

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.