PDA

View Full Version : saving the state of the ui



zgulser
24th March 2009, 07:48
hi,

I wonder if there is possible to return the .ui class initial state. Actually, I want to change the contents of the ui file by a button click and I want the ui file come back to it's initial state just after another button click in the same window.

is this possible?

thanks in advance

wysota
24th March 2009, 08:36
You can save all properties of all widgets in a window and then reset them back when you need it.

bair
24th March 2009, 10:53
I think QSettings is very convenient for such tasks.

Paladin12
24th March 2009, 12:17
To save a state use something like:



QSettings settings( "MyIniFile.ini", QSettings::IniFormat );
settings.beginGroup( "MyGroup" );
settings.setValue( "MyStateName", saveState(0) );
settings.endGroup();


To restore it use:



QSettings settings( "MyIniFile.ini", QSettings::IniFormat );
settings.beginGroup( "MyGroup" );
restoreState( settings.value( "MyStateName", QByteArray() ).toByteArray(), 0 );
settings.endGroup();


I develop mainly on Windows but prefer the INI storage format as it doesn't intefere with the registry and can be easily edited by hand (with the exception of states...).

You'll need to change your ini, group and state names accordingly (all the strings).

For more detailed work refer to QSettings.

Hope this helps.