Opened 9 months ago

Last modified 9 months ago

#18806 new defect

wxDialog::GetSize() and SetSize() change size of the dialog

Reported by: happythings Owned by:
Priority: normal Milestone:
Component: wxGTK Version: dev-latest
Keywords: Cc:
Blocked By: Blocking:
Patch: no


I want to save width and height of a dialog when the dialog is resized, and recover the size when the dialog object is created again, so i write code like patched codes. it seems right. but when the dialog is created and shown again, its height becomes saved height+28 pixels, i guess the extra height is the height of title bar of the dialog. I've only test it on ubuntu 16.04LTS and wxWidgets 3.1.3 and 3.1.4 with gtk2.
but on Windows, it's OK.
so, i think it's a bug.

Patch Codes:

void MainDialog::MainDialogBaseOnInitDialog( wxInitDialogEvent& event ) {
    std::ifstream ifs;"size.ini", std::ios::in);
    if (ifs.is_open()) {
        int w,h;

void MainDialog::MainDialogBaseOnSize( wxSizeEvent& event ) {
    wxSize size=event.GetSize();
    std::ofstream ofs;"size.ini", std::ios::out);
    ofs<<size.GetWidth()<< std::endl;
    ofs<<size.GetHeight()<< std::endl;

Change History (5)

comment:1 Changed 9 months ago by vadz

  • Component changed from GUI-all to wxGTK
  • Milestone 3.1.4 deleted
  • Summary changed from GetSize and SetSize of wxDialog seems to be optimized. to wxDialog::GetSize() and SetSize() change size of the dialog
  • Type changed from optimization to defect

You should consider using wxPersistentTLW class which already does what you want, but this won't really help with the bug in SetSize() I'm afraid.

I really thought we (well, Paul, to give credit where it's due) have fixed this by now, so I have no idea what could still be wrong. When you say that you've tested with 3.1.4, do you mean the current master (which commit?)?

Also, which desktop environment do you use on your Ubuntu 16.04 system?

comment:2 Changed 9 months ago by pcor

In general, this does work with GTK. There may be a problem with Ubuntu. I don't have much motivation anymore to try to figure out what is wrong with Ubuntu, particularly an older one.

A possible workaround would be to save and restore the client size.

comment:3 Changed 9 months ago by happythings

  • Cc 445210566@… added

the wxWidgets-3.1.4 is compiled from source codes from github on 2020-6-14

comment:4 Changed 9 months ago by happythings

  • Cc 445210566@… removed

by replace event.GetSize with GetClientSize and SetSize with SetClientSize,
All is Correct.

comment:5 Changed 9 months ago by pcor

There is now a report (#18854) that this happens with Ubuntu 20.04 GTK3 as well. Maybe someone who can reproduce this problem can try to figure out when it broke. Some possible suspects:

2c62ac41c1 (Set WM_CLASS class name as app display name, 2020-05-23)
0a56399f3c (Fix TLW decorations when GTK3 is using Client Side Decorations, 2020-01-30)
cec5d067e5 (Avoid deferred show when TLW decoration size is already known, 2018-04-28)

Note: See TracTickets for help on using tickets.