Unsolved Controlling size of a dock widget
-
I have a main window with a dockable widget at the bottom
In the constructor I have this code:
// // Set initial size of the bottom dock widget (pictureList) // resizeDocks({ pictureList }, { 150 }, Qt::Vertical); QSettings settings; settings.beginGroup("MainWindow"); restoreGeometry(settings.value("geometry").toByteArray()); restoreState(settings.value("windowState").toByteArray()); settings.endGroup();
and
void DeepSkyStacker::closeEvent(QCloseEvent* e) { // deleted stuff. QSettings settings; settings.beginGroup("MainWindow"); settings.setValue("geometry", saveGeometry()); settings.setValue("windowState", saveState()); settings.endGroup(); QTableView* tableView = this->findChild<QTableView*>("tableView"); settings.setValue("Dialogs/PictureList/TableView/HorizontalHeader/windowState", tableView->horizontalHeader()->saveState()); };
If the geometry and windowState settings don't exist, then the pictureList is sized to 150 high.
If I then manually change the size and close the application (which saves geometry and windowState), then next time it opens it does so with the new size (call this Size1). So far so good.
If I then adjust the size to Size2, then close and re-open the application, it opens with a size of Size1, not Size2.
What am I doing wrong please?
-
It's been a few days, and there's been no replies. I'm still baffled by this problem.
Cheers
David -
you can try to sync your settings file:
QSettings settings; settings.beginGroup("MainWindow"); settings.setValue("geometry", saveGeometry()); settings.setValue("windowState", saveState()); settings.endGroup(); settings.sync();
if you try to sync your settings i think it will change
-
void DeepSkyStacker::closeEvent(QCloseEvent* e) { // deleted stuff. QSettings settings; settings.beginGroup("MainWindow"); settings.setValue("geometry", saveGeometry()); settings.setValue("windowState", saveState()); settings.endGroup(); settings.sync(); QTableView* tableView = this->findChild<QTableView*>("tableView"); settings.setValue("Dialogs/PictureList/TableView/HorizontalHeader/windowState", tableView->horizontalHeader()->saveState()); };
-
I changed it to:
QSettings settings; settings.beginGroup("MainWindow"); settings.setValue("geometry", saveGeometry()); settings.setValue("windowState", saveState()); settings.endGroup(); QTableView* tableView = this->findChild<QTableView*>("tableView"); settings.setValue("Dialogs/PictureList/TableView/HorizontalHeader/windowState", tableView->horizontalHeader()->saveState()); settings.sync();
But that didn't change anything :(
Thanks
David -
@Perdrix
causeQSettings settings; settings.beginGroup("MainWindow"); settings.setValue("geometry", saveGeometry()); settings.setValue("windowState", saveState()); //settings.endGroup();//you ended up group here QTableView* tableView = this->findChild<QTableView*>("tableView"); settings.setValue("Dialogs/PictureList/TableView/HorizontalHeader/windowState", tableView->horizontalHeader()->saveState()); settings.endGroup();//move here and try again settings.sync();
-
I deliberately ended that group there as geometry and windowState belong under HKCU/SW/Appname/MainWindow, but the state of the Horizontal header belongs elsewhere.
Also reading the description of sync() - it clearly says: Writes any unsaved changes to permanent storage, and reloads any settings that have been changed in the meantime by another application.
This function is called automatically from QSettings's destructor and by the event loop at regular intervals, so you normally don't need to call it yourself.So I shouldn't need to call it anyway.
D.
-
Hi,
From old memories, I usually did not reload settings from constructors.
I would build the whole UI and then trigger the settings loading using a 0 based single shot QTimer.
That said, I am wondering whether there's a system cache doing something in between. I remember macOS having some funny behavior in that regard.
-
@SGaist Yes in fact I over simplified thing in my report of this issue.
The code I said was in the ctor is actually called from my onInitialise() mf which is called from showEvent():
void DeepSkyStacker::showEvent(QShowEvent* event) { if (!event->spontaneous()) { if (!initialised) { initialised = true; onInitialise(); } } // Invoke base class showEvent() return Inherited::showEvent(event); }
David
-
Did you check the content of the stored settings before restarting your application ?
-
I know there's something there, but I've no clue how to decode the stored byte arrays!
I changed the code a bit:
ZTRACE_RUNTIME("Restoring Window State and Position"); QSettings settings; settings.beginGroup("MainWindow"); auto geometry{ settings.value("geometry").toByteArray() }; ZTRACE_RUNTIME("Hex dump of geometry:"); ZTrace::dumpHex(geometry.constData(), geometry.length()); auto windowState{ settings.value("windowState").toByteArray() }; ZTRACE_RUNTIME("Hex dump of windowState:"); ZTrace::dumpHex(windowState.constData(), windowState.length()); restoreGeometry(geometry); restoreState(windowState); settings.endGroup();
And got:
00000029 2023/02/04 18:03:53.292 057720 0000ece8 >Restoring Window State and Position 00000030 2023/02/04 18:03:53.293 057720 0000ece8 >Hex dump of geometry: 00000031 2023/02/04 18:03:53.294 057720 0000ece8 >0000000003802780: 01D9D0CB 00030000 000004C0 00000252 ...............R 00000032 2023/02/04 18:03:53.294 057720 0000ece8 >0000000003802790: 00000895 0000060A 000004C0 00000270 ...............p 00000033 2023/02/04 18:03:53.295 057720 0000ece8 >00000000038027A0: 00000895 0000060A 00000000 00000000 ................ 00000034 2023/02/04 18:03:53.296 057720 0000ece8 >00000000038027B0: 0C000000 04C00000 02700000 08950000 .........p...... 00000035 2023/02/04 18:03:53.297 057720 0000ece8 >00000000038027C0: 060A .. 00000036 2023/02/04 18:03:53.298 057720 0000ece8 >Hex dump of windowState: 00000037 2023/02/04 18:03:53.299 057720 0000ece8 >000000000352F790: 000000FF 00000000 FD000000 02000000 ................ 00000038 2023/02/04 18:03:53.299 057720 0000ece8 >000000000352F7A0: 00000001 13000003 85FC0200 000001FB ................ 00000039 2023/02/04 18:03:53.300 057720 0000ece8 >000000000352F7B0: 00000016 00450078 0070006C 006F0072 .....E.x.p.l.o.r 00000040 2023/02/04 18:03:53.301 057720 0000ece8 >000000000352F7C0: 00650072 00420061 00720100 00000000 .e.r.B.a.r...... 00000041 2023/02/04 18:03:53.302 057720 0000ece8 >000000000352F7D0: 00038500 0001C600 07FFFF00 00000300 ................ 00000042 2023/02/04 18:03:53.302 057720 0000ece8 >000000000352F7E0: 0002BD00 000221FC 01000000 01FB0000 ......!......... 00000043 2023/02/04 18:03:53.303 057720 0000ece8 >000000000352F7F0: 00160050 00690063 00740075 00720065 ...P.i.c.t.u.r.e 00000044 2023/02/04 18:03:53.304 057720 0000ece8 >000000000352F800: 004C0069 00730074 01000001 19000002 .L.i.s.t........ 00000045 2023/02/04 18:03:53.305 057720 0000ece8 >000000000352F810: BD000002 7100FFFF FF000002 BD000001 ....q........... 00000046 2023/02/04 18:03:53.305 057720 0000ece8 >000000000352F820: 5E000000 01000000 04000000 01000000 ^............... 00000047 2023/02/04 18:03:53.306 057720 0000ece8 >000000000352F830: 08FC0000 0000 ...... 00000048 2023/02/04 18:03:53.345 057720 0000ece8 -void __cdecl DeepSkyStacker::onInitialise(void)
in my trace log file.
Does that help any?
-
@Perdrix said in Controlling size of a dock widget:
I've no clue how to decode the stored byte arrays!
QSettings::value()
hastoInt()
/toString()
functions since it storesQVariants
. -
@Pl45m4 Yes but that doesn't help in this case as these are just byte arrays.
-
@Perdrix said in Controlling size of a dock widget:
as these are just byte arrays.
Because you made them arrays :)
auto geometry{ settings.value("geometry").toByteArray() }; // just print it here with e.g. qDebug() qDebug() << settings.value("geometry")
-
I used toByteArray() to restore them to what was returned by saveGeometry() and saveState() both of which return a QByteArray array which I then saved into settings.
The only way to retrieve them correctly is to use toByteArray(), which is what I did.
To use toInt() or toString() on that data is meaningless as you would have realised had you bothered to look at the data.
D,
-
@Perdrix said in Controlling size of a dock widget:
To use toInt() or toString() on that data is meaningless as you would have realised had you bothered to look at the data.
I did, but I had in mind that "printing" the geometry would result in something like
Geometry (200, 200, QSize(150, 150))
-
That would be nice wouldn't it! Unfortunately ...
D.
-
@SGaist Did you see my post showing the content of the geometry and windowState variables? If so does that help identify the problem?
If not do you have any suggestions of what to do next?
Thanks
David -
@Perdrix it does not really.
What I would do is cleanup completely the settings storage to ensure there's no stale values.
Then I would run the application once to "initialize" the settings, extract the values for comparison. Then start the application again, change the size, rinse and repeat. Then compare the two settings.
If things get strange for the platform format (I am guessing Windows), I would try to compare with the init format.
-
- With no saved state/geometry, window opens with lower dock widget at 150 high. Then sized window and made dock widget large
00000033 2023/02/10 09:55:35.275 021380 00004e20 >Restoring Window State and Position (nothing to see here) 00000044 2023/02/10 09:56:29.013 021380 00004e20 >Saving Window State and Position 00000045 2023/02/10 09:56:29.013 021380 00004e20 >Hex dump of geometry: 00000046 2023/02/10 09:56:29.013 021380 00004e20 >000000000794A8D0: 01D9D0CB 00030000 000004C0 00000137 ...............7 00000047 2023/02/10 09:56:29.013 021380 00004e20 >000000000794A8E0: 0000083A 000004E6 000004C0 00000155 ...:...........U 00000048 2023/02/10 09:56:29.013 021380 00004e20 >000000000794A8F0: 0000083A 000004E6 00000000 00000000 ...:............ 00000049 2023/02/10 09:56:29.014 021380 00004e20 >000000000794A900: 0C000000 04C00000 01550000 083A0000 .........U...:.. 00000050 2023/02/10 09:56:29.014 021380 00004e20 >000000000794A910: 04E6 .. 00000051 2023/02/10 09:56:29.014 021380 00004e20 >Hex dump of windowState: 00000052 2023/02/10 09:56:29.014 021380 00004e20 >00000000079E9E60: 000000FF 00000000 FD000000 02000000 ................ 00000053 2023/02/10 09:56:29.014 021380 00004e20 >00000000079E9E70: 00000001 04000003 7CFC0200 000001FB ........|....... 00000054 2023/02/10 09:56:29.014 021380 00004e20 >00000000079E9E80: 00000016 00450078 0070006C 006F0072 .....E.x.p.l.o.r 00000055 2023/02/10 09:56:29.014 021380 00004e20 >00000000079E9E90: 00650072 00420061 00720100 00000000 .e.r.B.a.r...... 00000056 2023/02/10 09:56:29.015 021380 00004e20 >00000000079E9EA0: 00037C00 0001C600 07FFFF00 00000300 ..|............. 00000057 2023/02/10 09:56:29.015 021380 00004e20 >00000000079E9EB0: 00027100 000218FC 01000000 01FB0000 ..q............. 00000058 2023/02/10 09:56:29.015 021380 00004e20 >00000000079E9EC0: 00160050 00690063 00740075 00720065 ...P.i.c.t.u.r.e 00000059 2023/02/10 09:56:29.015 021380 00004e20 >00000000079E9ED0: 004C0069 00730074 01000001 0A000002 .L.i.s.t........ 00000060 2023/02/10 09:56:29.015 021380 00004e20 >00000000079E9EE0: 71000002 7100FFFF FF000002 71000001 q...q.......q... 00000061 2023/02/10 09:56:29.015 021380 00004e20 >00000000079E9EF0: 5E000000 01000000 04000000 01000000 ^............... 00000062 2023/02/10 09:56:29.015 021380 00004e20 >00000000079E9F00: 08FC0000 0000 ......
- Opened with the state saved above and then shrank the dock widget area
00000033 2023/02/10 09:56:34.098 020684 000061f8 >Restoring Window State and Position 00000034 2023/02/10 09:56:34.098 020684 000061f8 >Hex dump of geometry: 00000035 2023/02/10 09:56:34.098 020684 000061f8 >0000000003128A30: 01D9D0CB 00030000 000004C0 00000137 ...............7 00000036 2023/02/10 09:56:34.098 020684 000061f8 >0000000003128A40: 0000083A 000004E6 000004C0 00000155 ...:...........U 00000037 2023/02/10 09:56:34.098 020684 000061f8 >0000000003128A50: 0000083A 000004E6 00000000 00000000 ...:............ 00000038 2023/02/10 09:56:34.098 020684 000061f8 >0000000003128A60: 0C000000 04C00000 01550000 083A0000 .........U...:.. 00000039 2023/02/10 09:56:34.099 020684 000061f8 >0000000003128A70: 04E6 .. 00000040 2023/02/10 09:56:34.099 020684 000061f8 >Hex dump of windowState: 00000041 2023/02/10 09:56:34.099 020684 000061f8 >000000000310CAF0: 000000FF 00000000 FD000000 02000000 ................ 00000042 2023/02/10 09:56:34.099 020684 000061f8 >000000000310CB00: 00000001 04000003 7CFC0200 000001FB ........|....... 00000043 2023/02/10 09:56:34.099 020684 000061f8 >000000000310CB10: 00000016 00450078 0070006C 006F0072 .....E.x.p.l.o.r 00000044 2023/02/10 09:56:34.099 020684 000061f8 >000000000310CB20: 00650072 00420061 00720100 00000000 .e.r.B.a.r...... 00000045 2023/02/10 09:56:34.099 020684 000061f8 >000000000310CB30: 00037C00 0001C600 07FFFF00 00000300 ..|............. 00000046 2023/02/10 09:56:34.099 020684 000061f8 >000000000310CB40: 00027100 000218FC 01000000 01FB0000 ..q............. 00000047 2023/02/10 09:56:34.099 020684 000061f8 >000000000310CB50: 00160050 00690063 00740075 00720065 ...P.i.c.t.u.r.e 00000048 2023/02/10 09:56:34.100 020684 000061f8 >000000000310CB60: 004C0069 00730074 01000001 0A000002 .L.i.s.t........ 00000049 2023/02/10 09:56:34.100 020684 000061f8 >000000000310CB70: 71000002 7100FFFF FF000002 71000001 q...q.......q... 00000050 2023/02/10 09:56:34.100 020684 000061f8 >000000000310CB80: 5E000000 01000000 04000000 01000000 ^............... 00000051 2023/02/10 09:56:34.100 020684 000061f8 >000000000310CB90: 08FC0000 0000 ...... ... 00000058 2023/02/10 09:56:43.635 020684 000061f8 >Saving Window State and Position 00000059 2023/02/10 09:56:43.635 020684 000061f8 >Hex dump of geometry: 00000060 2023/02/10 09:56:43.635 020684 000061f8 >00000000079C8A10: 01D9D0CB 00030000 000004C0 00000137 ...............7 00000061 2023/02/10 09:56:43.635 020684 000061f8 >00000000079C8A20: 0000083A 000004E6 000004C0 00000155 ...:...........U 00000062 2023/02/10 09:56:43.636 020684 000061f8 >00000000079C8A30: 0000083A 000004E6 00000000 00000000 ...:............ 00000063 2023/02/10 09:56:43.636 020684 000061f8 >00000000079C8A40: 0C000000 04C00000 01550000 083A0000 .........U...:.. 00000064 2023/02/10 09:56:43.636 020684 000061f8 >00000000079C8A50: 04E6 .. 00000065 2023/02/10 09:56:43.636 020684 000061f8 >Hex dump of windowState: 00000066 2023/02/10 09:56:43.636 020684 000061f8 >0000000007A32520: 000000FF 00000000 FD000000 02000000 ................ 00000067 2023/02/10 09:56:43.636 020684 000061f8 >0000000007A32530: 00000001 04000003 7CFC0200 000001FB ........|....... 00000068 2023/02/10 09:56:43.636 020684 000061f8 >0000000007A32540: 00000016 00450078 0070006C 006F0072 .....E.x.p.l.o.r 00000069 2023/02/10 09:56:43.637 020684 000061f8 >0000000007A32550: 00650072 00420061 00720100 00000000 .e.r.B.a.r...... 00000070 2023/02/10 09:56:43.637 020684 000061f8 >0000000007A32560: 00037C00 0001C600 07FFFF00 00000300 ..|............. 00000071 2023/02/10 09:56:43.637 020684 000061f8 >0000000007A32570: 00027100 000110FC 01000000 01FB0000 ..q............. 00000072 2023/02/10 09:56:43.637 020684 000061f8 >0000000007A32580: 00160050 00690063 00740075 00720065 ...P.i.c.t.u.r.e 00000073 2023/02/10 09:56:43.637 020684 000061f8 >0000000007A32590: 004C0069 00730074 01000001 0A000002 .L.i.s.t........ 00000074 2023/02/10 09:56:43.637 020684 000061f8 >0000000007A325A0: 71000002 7100FFFF FF000002 71000002 q...q.......q... 00000075 2023/02/10 09:56:43.637 020684 000061f8 >0000000007A325B0: 66000000 01000000 04000000 01000000 f............... 00000076 2023/02/10 09:56:43.637 020684 000061f8 >0000000007A325C0: 08FC0000 0000 ......
- Opened again - but dock widget area still came up large .
00000033 2023/02/10 09:57:01.941 020816 000048cc >Restoring Window State and Position 00000034 2023/02/10 09:57:01.941 020816 000048cc >Hex dump of geometry: 00000035 2023/02/10 09:57:01.941 020816 000048cc >0000000002FB3200: 01D9D0CB 00030000 000004C0 00000137 ...............7 00000036 2023/02/10 09:57:01.941 020816 000048cc >0000000002FB3210: 0000083A 000004E6 000004C0 00000155 ...:...........U 00000037 2023/02/10 09:57:01.941 020816 000048cc >0000000002FB3220: 0000083A 000004E6 00000000 00000000 ...:............ 00000038 2023/02/10 09:57:01.941 020816 000048cc >0000000002FB3230: 0C000000 04C00000 01550000 083A0000 .........U...:.. 00000039 2023/02/10 09:57:01.942 020816 000048cc >0000000002FB3240: 04E6 .. 00000040 2023/02/10 09:57:01.942 020816 000048cc >Hex dump of windowState: 00000041 2023/02/10 09:57:01.942 020816 000048cc >0000000003075CB0: 000000FF 00000000 FD000000 02000000 ................ 00000042 2023/02/10 09:57:01.942 020816 000048cc >0000000003075CC0: 00000001 04000003 7CFC0200 000001FB ........|....... 00000043 2023/02/10 09:57:01.942 020816 000048cc >0000000003075CD0: 00000016 00450078 0070006C 006F0072 .....E.x.p.l.o.r 00000044 2023/02/10 09:57:01.942 020816 000048cc >0000000003075CE0: 00650072 00420061 00720100 00000000 .e.r.B.a.r...... 00000045 2023/02/10 09:57:01.942 020816 000048cc >0000000003075CF0: 00037C00 0001C600 07FFFF00 00000300 ..|............. 00000046 2023/02/10 09:57:01.942 020816 000048cc >0000000003075D00: 00027100 000110FC 01000000 01FB0000 ..q............. 00000047 2023/02/10 09:57:01.943 020816 000048cc >0000000003075D10: 00160050 00690063 00740075 00720065 ...P.i.c.t.u.r.e 00000048 2023/02/10 09:57:01.943 020816 000048cc >0000000003075D20: 004C0069 00730074 01000001 0A000002 .L.i.s.t........ 00000049 2023/02/10 09:57:01.943 020816 000048cc >0000000003075D30: 71000002 7100FFFF FF000002 71000002 q...q.......q... 00000050 2023/02/10 09:57:01.943 020816 000048cc >0000000003075D40: 66000000 01000000 04000000 01000000 f............... 00000051 2023/02/10 09:57:01.943 020816 000048cc >0000000003075D50: 08FC0000 0000 ......