PDA

View Full Version : QDockWidget saveState and restoreState



^NyAw^
4th December 2009, 11:10
Hi,

I have an application that have one QDockWidget. The application have two user types and the widgets are moved to different positions depending on the current user. The user can move and resize the Dock. Then, using a shortCut I change the features of the Dock to not let the user move or resize the Dock(with this I can define the user GUI and lock it), but if I change the user to the second one and return to the first, the features(closeable, floatable,...) of the Dock are not restored.
I use saveState and restoreState for the different users, but only the position and size are restored.
So, the features of the Dock are not stored?

Thanks,

stefanadelbert
26th February 2010, 00:24
I'm having a similar problem at the moment where some of the states of QDockWidgets are not restored (like floatable). I'm looking into this at the moment and will hopefully find a solution.

stefanadelbert
1st March 2010, 04:36
I've managed to narrow down the strange behaviour to nested dock widgets.


Call QMainWindow::saveState on a main window with two docked QDockWidgets which are nested/tabbed
Float one of the nested/tabbed QDockWidgets
Call QMainWindow::restoreState


EXPECT: Both QDockWidgets to be nested/tabbed as they were before QMainWindow::saveState.
ACTUAL: The docked, nested/tabbed state of the QDockWidget is not restored - it's left floating.

I have not had time to create example code to demonstrate this. Would it be of use to anyone?

DizL
28th January 2016, 10:56
The same problem :/

In general I have a big problem with restoreState/restoreGeometry, QSettings ini file looks good after saving (objectname (is unique), dockwidget area, geometry),

[docks]
dock\1\objectName="Type_1;5"
dock\1\area=2
dock\1\geometry=@ByteArray(\x1\xd9\xd0\xcb\0\x2\0\ 0\0\0\x4\xc8\0\0\x1\x45\0\0\x6\x31\0\0\x2H\0\0\x4\ xc8\0\0\x1\x45\0\0\x6\x31\0\0\x2H\0\0\0\0\0\0\0\0\ a\x80)
dock\2\objectName="Type_2;3"
dock\2\area=2
dock\2\geometry=@ByteArray(\x1\xd9\xd0\xcb\0\x2\0\ 0\0\0\x4\xc8\0\0\0\x1e\0\0\x6\x31\0\0\x1\x42\0\0\x 4\xc8\0\0\0\x1e\0\0\x6\x31\0\0\x1\x42\0\0\0\0\0\0\ 0\0\a\x80)
dock\3\objectName="Type_3;4"
dock\3\area=8
dock\3\geometry=@ByteArray(\x1\xd9\xd0\xcb\0\x2\0\ 0\0\0\0\0\0\0\x2\xbc\0\0\x6\x31\0\0\x3s\0\0\0\0\0\ 0\x2\xbc\0\0\x6\x31\0\0\x3s\0\0\0\0\0\0\0\0\a\x80)
dock\4\objectName="Type_4;7"
dock\4\area=2
dock\4\geometry=@ByteArray(\x1\xd9\xd0\xcb\0\x2\0\ 0\0\0\x4\xc8\0\0\x2K\0\0\x6\x31\0\0\x2\xb9\0\0\x4\ xc8\0\0\x2K\0\0\x6\x31\0\0\x2\xb9\0\0\0\0\0\0\0\0\ a\x80)
dock\5\objectName="Type_5;2"
dock\5\area=1
dock\5\geometry=@ByteArray(\x1\xd9\xd0\xcb\0\x2\0\ 0\0\0\0\0\0\0\0\x1e\0\0\x1O\0\0\x1\xb1\0\0\0\0\0\0 \0\x1e\0\0\x1O\0\0\x1\xb1\0\0\0\0\0\0\0\0\a\x80)
dock\6\objectName="Type_6;5"
dock\6\area=1
dock\6\geometry=@ByteArray(\x1\xd9\xd0\xcb\0\x2\0\ 0\0\0\0\0\0\0\x1\xb4\0\0\x1O\0\0\x2\xb9\0\0\0\0\0\ 0\x1\xb4\0\0\x1O\0\0\x2\xb9\0\0\0\0\0\0\0\0\a\x80)
dock\7\objectName="Type_7;3"
dock\7\area=0
dock\7\geometry=@ByteArray(\x1\xd9\xd0\xcb\0\x2\0\ 0\0\0\f\x84\0\0\x2\x39\0\0\xe(\0\0\x3\x96\0\0\f\x8 c\0\0\x2X\0\0\xe \0\0\x3\x8e\0\0\0\x1\0\0\0\0\a\x80)
dock\size=7

[Window]
geometry=@ByteArray(\x1\xd9\xd0\xcb\0\x2\0\0\0\0\0 \x80\0\0\0\x33\0\0\x6\xc1\0\0\x3\xe1\0\0\0\x88\0\0 \0R\0\0\x6\xb9\0\0\x3\xd9\0\0\0\0\0\0\0\0\a\x80)
windowState="@ByteArray(\0\0\0\xff\0\0\0\0\xfd\0\0\0\x3\0\0\0\0 \0\0\x1P\0\0\x2\x9c\xfc\x2\0\0\0\x2\xfb\0\0\0\x1a\ 0T\0\x65\0l\0\x65\0m\0\x65\0t\0r\0y\0_\0\x35\0;\0\ x32\x1\0\0\0\x1e\0\0\x1\x94\0\0\x1!\0\xff\xff\xff\ xfb\0\0\0\x18\0M\0\x61\0i\0n\0V\0i\0\x65\0w\0_\0\x 36\0;\0\x35\x1\0\0\x1\xb4\0\0\x1\x6\0\0\x1\x4\0\xf f\xff\xff\0\0\0\x1\0\0\x1j\0\0\x2\x9c\xfc\x2\0\0\0 \x3\xfb\0\0\0*\0\x41\0r\0t\0i\0\x66\0i\0\x63\0i\0\ x61\0l\0H\0o\0r\0i\0z\0o\0n\0_\0\x32\0;\0\x33\x1\0 \0\0\x1e\0\0\x1%\0\0\0\xc8\0\xff\xff\xff\xfb\0\0\0 \x18\0M\0\x61\0i\0n\0V\0i\0\x65\0w\0_\0\x31\0;\0\x 35\x1\0\0\x1\x45\0\0\x1\x4\0\0\x1\x4\0\xff\xff\xff \xfb\0\0\0\x1a\0L\0o\0g\0P\0l\0\x61\0y\0\x65\0r\0_ \0\x34\0;\0\x37\x1\0\0\x2K\0\0\0o\0\0\0o\0\xff\xff \xff\0\0\0\x3\0\0\x6\x32\0\0\0\xb8\xfc\x1\0\0\0\x1 \xfb\0\0\0&\0W\0\x61\0y\0P\0o\0i\0n\0t\0s\0W\0i\0\x64\0g\0\x6 5\0t\0_\0\x33\0;\0\x34\x1\0\0\0\0\0\0\x6\x32\0\0\x 3O\0\xff\xff\xff\0\0\x3t\0\0\x2\x9c\0\0\0\x4\0\0\0 \x4\0\0\0\b\0\0\0\b\xfc\0\0\0\0)"
size=@Size(1586 904)
pos=@Point(128 51)
but after loading it looks bad:| (especially in case when added before new dockwidgets, and removed some of old) :/
this is how i load it


QSettings settings(QApplication::applicationDirPath() + fileini, QSettings::IniFormat);

settings.beginGroup("docks");

int DocksCount = settings.beginReadArray("dock");
if(DocksCount > 0)
{
for(int i = 0; i < DocksCount; i++)
{
settings.setArrayIndex(i);

QString objectName = settings.value("objectName").toString();

QDockWidget* dock = addSubWindow(objectName);
if(dock)
{
Qt::DockWidgetArea area = static_cast<Qt::DockWidgetArea>(settings.value("area").toInt());
this->addDockWidget(area, dock);
dock->restoreGeometry(settings.value("geometry").toByteArray());
}
}
}
settings.endArray();
settings.endGroup();

settings.beginGroup("Window");
restoreGeometry(settings.value("geometry").toByteArray());
restoreState(settings.value("windowState").toByteArray());

resize(settings.value("size", QSize(1200, 800)).toSize());
move(settings.value("pos", QPoint(0, 0)).toPoint());


any help?

Regards,
DizL