From 098161c4dea1d2f3cc27af996a70ab401456045e Mon Sep 17 00:00:00 2001 From: ali kettab Date: Sun, 1 Oct 2023 18:33:48 +0100 Subject: [PATCH] Make sure a generic window (e.g. wxPanel) is created with a valid size Such windows will not be shown and are ignored by Qt if added directly as children to another window not managed by any sizer. --- src/qt/window.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/qt/window.cpp b/src/qt/window.cpp index bb4b3f45bd..cbdde20830 100644 --- a/src/qt/window.cpp +++ b/src/qt/window.cpp @@ -350,6 +350,8 @@ bool wxWindowQt::Create( wxWindowQt * parent, wxWindowID id, const wxPoint & pos // that a generic control, like wxPanel, is being created, so we need a very // simple control as a base: + wxSize initialSize = size; + if ( GetHandle() == nullptr ) { if ( style & (wxHSCROLL | wxVSCROLL) ) @@ -364,6 +366,13 @@ bool wxWindowQt::Create( wxWindowQt * parent, wxWindowID id, const wxPoint & pos } else m_qtWindow = new wxQtWidget( parent, this ); + + // The default size of a generic control (e.g. wxPanel) is (0, 0) when created and + // is ignored by Qt unless the widget is already assigned a valid size or is added + // to a QLayout to be managed with. The value 20 seems to be the default under wxMSW. + // Do not pass 'initialSize' to CreateBase() below, as it will be taken as the minimum + // size of the control, which is not the intention here. + initialSize.SetDefaults(wxSize(20, 20)); } if ( !wxWindowBase::CreateBase( parent, id, pos, size, style, wxDefaultValidator, name )) @@ -375,11 +384,11 @@ bool wxWindowQt::Create( wxWindowQt * parent, wxWindowID id, const wxPoint & pos if ( pos != wxDefaultPosition ) p = pos; - DoMoveWindow( p.x, p.y, size.GetWidth(), size.GetHeight() ); + DoMoveWindow( p.x, p.y, initialSize.GetWidth(), initialSize.GetHeight() ); PostCreation(); - return ( true ); + return true; } void wxWindowQt::PostCreation(bool generic)