PDA

View Full Version : qt savegeometry multiple document interface



knobby67
21st August 2014, 17:42
Hi All,
I'm working with an MDI. The mainwindow holds several dialogs that are shown by a view button, using mGameDialog->show( ) mGameDialog->raise( );. Everything runs fine. I can work on, resize and move the dialogs. However When I use savegeometry to save my set up all that is saved is the main window size/position ect, not the dialogs. I would like it so that when I open all the dialogs are shown in the position they were left in. Can anyone point me in the correct direction? My save and open code are as below.


void MainWindow::GUI_savesettings( void )
{

appSettings->setValue("state/mainWindowState", saveState( ) );
appSettings->setValue("geometry/mainWindowGeometry",saveGeometry( ) );

}


void MainWindow::GUI_loadsettings( void )
{
QByteArray stateData = appSettings->value("state/mainWindowState").toByteArray();
QByteArray geometryData = appSettings->value("geometry/mainWindowGeometry").toByteArray();


restoreState( stateData );
restoreGeometry( geometryData );

}


Thanks All.

anda_skoa
22nd August 2014, 10:15
Just save the geometry of each dialog as well. Probably also whether a dialog is currently shown or not.

Cheers,
_

knobby67
22nd August 2014, 18:27
Thanks, the issue is I don't know how to do that? For example if I have a dialog set in my mainwindow.h as


private:
Ui::MainWindow *ui;

QSettings *appSettings;

/*windows that can be drawn permently*/

GameviewDialog *mGameViewDialog;


how would I tell it to save mGameViewDialog? How would I ajust the below to point at that dialog?


appSettings->setValue("state/mainWindowState", saveState( ) );
appSettings->setValue("geometry/mainWindowGeometry",saveGeometry( ) );

I can't find this documented anywhere or any tutorials that tell you how to do it.
Thanks

should add I've tried


appSettings->setValue("geometry/ViewGeometry",GameViewDialog->saveGeometry( ) );

then called to restore, however I get a segmentation fault


mGameViewDialog->restoreGeometry( geometryData );


Added after 59 minutes:

Thankyou I've solved it. I was calling the loadgui function from my mainwindow constructor. However I was doing so before setting up the dialogs. eg



/*lets restore*/
GUI_loadsettings( );
mGameDialog = new GameDialog( this );


rather than


mGameDialog = new GameDialog( this );
/*lets restore*/
GUI_loadsettings( );


:s