Use correct column attributes when drawing wxListCtrl (PR #25962)

19 views
Skip to first unread message

Maarten

unread,
Nov 9, 2025, 6:25:29 AM (2 days ago) Nov 9
to wx-...@googlegroups.com, Subscribed

When a column is custom drawn, it uses the wxItemAttr of the column being updated to redraw all columns. Fix this by requesting the column attributes of each column that is drawn.

See #25633 (not sure if you can close this, because it is about more than wxListCtrl)

cc @Crementif This shouldn't affect your fixes from #25950 but I'd appreciate if you could review this to make sure all still works fine. Thank you.

You can reproduce the problem with the following patch. Open the listctrl sample in dark mode, and select the virtual view (f7). Without this PR, all columns have the same colour, with this PR columns have the correct different colour.

 samples/listctrl/listtest.cpp | 12 ++++++++++++
 samples/listctrl/listtest.h   |  1 +
 2 files changed, 13 insertions(+)

diff --git a/samples/listctrl/listtest.cpp b/samples/listctrl/listtest.cpp
index 6cb49bcf871..48dac3cef12 100644
--- a/samples/listctrl/listtest.cpp
+++ b/samples/listctrl/listtest.cpp
@@ -1536,6 +1536,18 @@ int MyListCtrl::OnGetItemColumnImage(long item, long column) const
     return -1;
 }
 
+wxItemAttr* MyListCtrl::OnGetItemColumnAttr(long item, long column) const
+{
+    static wxItemAttr attr(*wxRED, wxNullColour, wxNullFont);
+    if (column == 0)
+        attr.SetTextColour(wxColour(0xFF, 0x00, 0x00));
+    if (column == 1)
+        attr.SetTextColour(wxColour(0x00, 0x00, 0xFF));
+    if ((item + column) % 5 == 0)
+        attr.SetTextColour(wxColour(0x00, 0xFF, 0x00));
+    return &attr;
+}
+
 wxItemAttr *MyListCtrl::OnGetItemAttr(long item) const
 {
     // test to check that RefreshItem() works correctly: when m_updated is
diff --git a/samples/listctrl/listtest.h b/samples/listctrl/listtest.h
index ffa4190548a..2b1e8369560 100644
--- a/samples/listctrl/listtest.h
+++ b/samples/listctrl/listtest.h
@@ -84,6 +84,7 @@ private:
     virtual wxString OnGetItemText(long item, long column) const override;
     virtual bool OnGetItemIsChecked(long item) const override;
     virtual int OnGetItemColumnImage(long item, long column) const override;
+    virtual wxItemAttr *OnGetItemColumnAttr(long item, long column) const override;
     virtual wxItemAttr *OnGetItemAttr(long item) const override;
 
     long m_updated;

You can view, comment on, or merge this pull request online at:

  https://github.com/wxWidgets/wxWidgets/pull/25962

Commit Summary

  • 7f3e783 Use correct column attributes when drawing wxListCtrl

File Changes

(1 file)

Patch Links:


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/pull/25962@github.com>

VZ

unread,
Nov 9, 2025, 10:07:03 AM (2 days ago) Nov 9
to wx-...@googlegroups.com, Subscribed

@vadz commented on this pull request.

Thanks for fixing this, and it's a minor detail, but could we perhaps pass a vector<wxItemAttr*> instead of a function/lambda? It seems weird to use the latter for this, if using vector is difficult/undesirable, I'd rather consider making these functions member functions (or maybe just renaming DoGetItemColumnAttr() to MSWGetItemColumnAttr() and making it public so that they could call it).


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/pull/25962/review/3440083636@github.com>

Maarten

unread,
Nov 9, 2025, 10:11:48 AM (2 days ago) Nov 9
to wx-...@googlegroups.com, Subscribed
MaartenBent left a comment (wxWidgets/wxWidgets#25962)

I tried using vector at first, but it doesn't work with my example, where wxItemAttr is static. Because all pointers reference the same object and will have the values of the last called GetItemColumnAttr.

I'll try the MSWGetItemColumnAttr suggestion.


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/pull/25962/c3508441383@github.com>

Crementif

unread,
Nov 10, 2025, 9:56:51 AM (yesterday) Nov 10
to wx-...@googlegroups.com, Subscribed
Crementif left a comment (wxWidgets/wxWidgets#25962)

Sure, I can test whether it breaks anything once you've tried the suggestion that vadz mentioned.
Reading it, I think these changes shouldn't affect anything, as long as the background color clear checks whether the row/item is selected.


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/pull/25962/c3512202485@github.com>

Reply all
Reply to author
Forward
0 new messages