Results 1 to 4 of 4

Thread: QMainWindow::restoreState

  1. #1
    Join Date
    May 2008
    Location
    Ukraine, Berdyansk
    Posts
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default QMainWindow::restoreState

    Qt Code:
    1. #include <QtCore>
    2. #include <QtGui>
    3.  
    4. class Window: public QMainWindow
    5. {
    6. public:
    7. Window(void):QMainWindow()
    8. {
    9. t=new QToolBar("Toolbar1",this);
    10. t->addAction(new QAction("Act1",this));
    11. t->addAction(new QAction("Act2",this));
    12. t->addAction(new QAction("Act3",this));
    13. addToolBar(t);
    14.  
    15. QSettings s("Trolltech","TestAPP");
    16. if(restoreState(s.value("MainWindowState").toByteArray()))
    17. {
    18. // creation of second toolbar depends on user interaction
    19. // for example second run
    20. t=new QToolBar("Toolbar2",this);
    21. t->addAction(new QAction("Act1",this));
    22. t->addAction(new QAction("Act2",this));
    23. t->addAction(new QAction("Act3",this));
    24. addToolBar(t);
    25. }
    26.  
    27. }
    28. ~Window(void)
    29. {
    30. QSettings s("Trolltech","TestAPP");
    31. s.setValue("MainWindowState",saveState());
    32. }
    33. private:
    34. };
    35.  
    36.  
    37. int main(int argc, char *argv[])
    38. {
    39. QApplication app(argc, argv);
    40. Window window;
    41. window.show();
    42. return app.exec();
    43. }
    To copy to clipboard, switch view to plain text mode 

    why toolbars layout differently when state restored and when i dont use state restore function?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QMainWindow::restoreState

    Maybe because you save the state in destructor? It might be too late. What does s.value("MainWindowState").isValid() return?

  3. #3
    Join Date
    May 2008
    Location
    Ukraine, Berdyansk
    Posts
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QMainWindow::restoreState

    it isn`t too late.
    issue is that if toolbar created after state restore toolbar placed at end of line with minimum size.

    Do you run example?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QMainWindow::restoreState

    This seems to work:
    Qt Code:
    1. Window(void):QMainWindow()
    2. {
    3. t=new QToolBar("Toolbar1",this);
    4. t->setObjectName( "aaa" );
    5. t->addAction(new QAction("Act1",this));
    6. t->addAction(new QAction("Act2",this));
    7. t->addAction(new QAction("Act3",this));
    8. addToolBar(t);
    9.  
    10. t=new QToolBar("Toolbar2",this);
    11. t->setObjectName( "bbb" );
    12. t->addAction(new QAction("Act1",this));
    13. t->addAction(new QAction("Act2",this));
    14. t->addAction(new QAction("Act3",this));
    15. addToolBar(t);
    16.  
    17. QSettings s("Trolltech","TestAPP");
    18. restoreState(s.value("MainWindowState").toByteArray());
    19. }
    To copy to clipboard, switch view to plain text mode 
    (note the calls to setObjectName())

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.