From f2923d49e1f3e839cdd27dc745a93c7ebfb379da Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 1 Apr 2020 01:08:41 +0200 Subject: [PATCH] Update native wxGrid header on DPI change Simply resize all columns to their effective widths when using native wxHeaderCtrl for the grid. --- src/generic/grid.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index 6d31306069..e935a321f5 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -5376,7 +5376,11 @@ void wxGrid::OnDPIChanged(wxDPIChangedEvent& event) } } - // Similarly for columns. + // Similarly for columns, except that here we need to update the native + // control even if none of the widths had been changed, as it's not going + // to do it on its own when redisplayed. + wxHeaderCtrl* const + colHeader = m_useNativeHeader ? GetGridColHeader() : NULL; if ( !m_colWidths.empty() ) { int total = 0; @@ -5392,6 +5396,16 @@ void wxGrid::OnDPIChanged(wxDPIChangedEvent& event) m_colWidths[i] = width; m_colRights[i] = total; + + if ( colHeader ) + colHeader->UpdateColumn(i); + } + } + else if ( colHeader ) + { + for ( int i = 0; i < m_numCols; ++i ) + { + colHeader->UpdateColumn(i); } }