wxGrid breaks on DPI change if hidden columns are present (Issue #26079)

26 views
Skip to first unread message

dsa-t

unread,
Jan 7, 2026, 11:42:07 PM (4 days ago) Jan 7
to wx-...@googlegroups.com, Subscribed
dsa-t created an issue (wxWidgets/wxWidgets#26079)

Description

If wxGrid has hidden columns, then a DPI change occurs, XYToCell stops working correctly and some rendering artifacts appear when scrolling.

This can be traced down to this code:

https://github.com/wxWidgets/wxWidgets/blob/1b582af60d99388b56b383fe240b647387a5e4b4/src/generic/grid.cpp#L6245-L6264

Hidden columns have negative width, so due to the condition if ( width <= 0 ), m_colRights values are not updated which breaks binary search in wxGrid::PosToLinePos.

IMO, negative values in m_colWidths should be scaled too.

image.png (view on web)

Platform and version information

  • wxWidgets version you use: 3.3
  • wxWidgets port you use: wxMSW
  • OS and its version: Windows 11

KiCad issue: https://gitlab.com/kicad/code/kicad/-/issues/15641


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/26079@github.com>

VZ

unread,
Jan 8, 2026, 10:02:32 AM (3 days ago) Jan 8
to wx-...@googlegroups.com, Subscribed
vadz left a comment (wxWidgets/wxWidgets#26079)

I see, thanks. Would just this fix the problem?

diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp
index f33c9fc1a3..1ee736f306 100644
--- a/src/generic/grid.cpp
+++ b/src/generic/grid.cpp
@@ -6225,14 +6225,16 @@ void wxGrid::OnDPIChanged(wxDPIChangedEvent& event)
         {
             int height = m_rowHeights[i];
 
-            // Skip hidden rows.
-            if ( height <= 0 )
-                continue;
-
+            // Note that even hidden rows heights must be scaled to ensure that
+            // they appear in the expected size if they are shown again.
             height = event.ScaleY(height);
-            total += height;
 
             m_rowHeights[i] = height;
+
+            // But don't count hidden rows for the total height.
+            if ( height > 0 )
+                total += height;
+
             m_rowBottoms[i] = total;
         }
     }
@@ -6249,13 +6251,13 @@ void wxGrid::OnDPIChanged(wxDPIChangedEvent& event)
         {
             int width = m_colWidths[i];
 
-            if ( width <= 0 )
-                continue;
-
             width = event.ScaleX(width);
-            total += width;
 
             m_colWidths[i] = width;
+
+            if ( width > 0 )
+                total += width;
+
             m_colRights[i] = total;
 
             if ( colHeader )


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/26079/3724271670@github.com>

dsa-t

unread,
Jan 8, 2026, 10:30:22 AM (3 days ago) Jan 8
to wx-...@googlegroups.com, Subscribed
dsa-t left a comment (wxWidgets/wxWidgets#26079)

Thanks, looks like this should fix it.

(can't test in KiCad currently)


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/26079/3724395321@github.com>

VZ

unread,
Jan 8, 2026, 5:01:36 PM (3 days ago) Jan 8
to wx-...@googlegroups.com, Subscribed
vadz left a comment (wxWidgets/wxWidgets#26079)

I'll push this soon and will backport this to 3.2 later if you can confirm that this fixes the problem in KiCad. TIA!


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/26079/3726015255@github.com>

VZ

unread,
Jan 8, 2026, 5:05:03 PM (3 days ago) Jan 8
to wx-...@googlegroups.com, Subscribed

Closed #26079 as completed via 4bd7fe2.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issue/26079/issue_event/21933886511@github.com>

Reply all
Reply to author
Forward
0 new messages