aarelovich
aarelovich

Reputation: 5556

Qt: Restoring the geometry of QTextEdit fails

I'm attempting to restore the geometry (mostly the sizes) of a TabWidget, a ListView and a TextEdit. All of this was designed with the QtDesginer so I didn't write anycode. The TabWidget and the ListView where "grouped together with in a horizontal layout with a splitter" and the resulting group was "grouped together in a vertical layout with a splitter" and the textedit at the bottom. The group was set in a grid layout on the main window.

I load the settings in the window constructor like this:

   restoreGeometry(settings.value("main_interface").toByteArray());
   restoreState(settings.value("main_window_state").toByteArray());
   ui->twConversations->setGeometry(settings.value("conversations").toRect());
   ui->lvContacts->setGeometry(settings.value("contacts").toRect());
   ui->teUserInput->setGeometry(settings.value("lineinput").toRect());
   ui->spEditRest->setGeometry(settings.value("vertical_space").toRect());
   userID = settings.value("user_id").toString();
   doesUserExist = !userID.isEmpty();

You can see that I've even tried to save the splitter geometry to see if it made any difference. It didn't.

The save settings function is called when the window closes with this code:

QSettings settings(SETTINGS_FILE,QSettings::IniFormat);
settings.setValue("main_interface",this->saveGeometry());
settings.setValue("main_window_state",this->saveState());
settings.setValue("conversations",ui->twConversations->geometry());
settings.setValue("contacts",ui->lvContacts->geometry());
settings.setValue("lineinput",ui->teUserInput->geometry());
settings.setValue("vertical_space",ui->spEditRest->geometry());
settings.setValue("user_id",userID);

When the INI does not exist it is created with these values:

[General]
main_interface=@ByteArray(\x1\xd9\xd0\xcb\0\x1\0\0\0\0\a\x80\0\0\0\0\0\0\v-\0\0\x2\xf1\0\0\a\x83\0\0\0\x17\0\0\v*\0\0\x2\xed\0\0\0\x2\0\0)
main_window_state=@ByteArray(\0\0\0\xff\0\0\0\0\xfd\0\0\0\0\0\0\x3\xa8\0\0\x2\xaa\0\0\0\x4\0\0\0\x4\0\0\0\b\0\0\0\b\xfc\0\0\0\x1\0\0\0\x2\0\0\0\x1\0\0\0\x16\0m\0\x61\0i\0n\0T\0o\0o\0l\0\x42\0\x61\0r\x1\0\0\0\0\xff\xff\xff\xff\0\0\0\0\0\0\0\0)
conversations=@Rect(0 0 206 329)
contacts=@Rect(209 0 705 329)
lineinput=@Rect(0 332 914 328)
vertical_space=@Rect(11 11 914 660)
user_id=

Then I shrink the textedit (identified as lineinput in the ini) and close. The resulting INI value is this:

[General]
main_interface=@ByteArray(\x1\xd9\xd0\xcb\0\x1\0\0\0\0\a\x80\0\0\0\0\0\0\v-\0\0\x2\xf1\0\0\a\x83\0\0\0\x17\0\0\v*\0\0\x2\xed\0\0\0\x2\0\0)
main_window_state=@ByteArray(\0\0\0\xff\0\0\0\0\xfd\0\0\0\0\0\0\x3\xa8\0\0\x2\xaa\0\0\0\x4\0\0\0\x4\0\0\0\b\0\0\0\b\xfc\0\0\0\x1\0\0\0\x2\0\0\0\x1\0\0\0\x16\0m\0\x61\0i\0n\0T\0o\0o\0l\0\x42\0\x61\0r\x1\0\0\0\0\xff\xff\xff\xff\0\0\0\0\0\0\0\0)
conversations=@Rect(0 0 206 581)
contacts=@Rect(209 0 705 581)
lineinput=@Rect(0 584 914 76)
vertical_space=@Rect(11 11 914 660)
user_id=

I can see that the height of the lineinput changed from 328 to 76 however when I open the app again the size is not reduced. Saving it again will again save 328.

Can anyone tell me what is going on?

Upvotes: 0

Views: 178

Answers (1)

Fabio
Fabio

Reputation: 2602

It's not a good idea resize a widget that is inside a layout, because the layout manage its size. You can restore the main window geometry and also restore the state of the splitters (saveState(), restoreState()) (not the geometry of the splitters)

Upvotes: 1

Related Questions