Forcing wxListView to draw empty columns

17 views
Skip to first unread message

Andreas Falkenhahn

unread,
Sep 21, 2021, 9:35:45 AM9/21/21
to wx-u...@googlegroups.com
I have a wxListView with 7 columns. The second column contains text, all the other columns contain a 24x24 icon. Sometimes, however, I don't want the icon to be shown. Instead, the column should be empty. I'm having some difficulties getting this to work correctly because it looks like empty columns are automatically hidden. See shot0.png. This is what my listview looks like when columns 4, 6 and 7 don't have any icon. wxListView seems to hide them automatically then so that it looks as if the listview had only 4 columns.

I've tried the following to solve this issue:

1) Create a dummy 24x24 icon which is completely transparent. This doesn't work. For some reason, completely transparent icons are drawn as a 24x24 black rectangle. See shot1.png. I don't actually understand why this happens and this looks like a bug to me.

2) As a test to see why 1) doesn't work, I've made a single pixel visible in the 24x24 icon. Now it suddenly works correctly but of course it looks ugly because there's a random pixel now in the top-left corner of the column. See shot2.png.

3) Make the whole 24x24 icon opaque and white. This solves the problem but of course this won't look correctly if the listview's background colour isn't white.

The best way that I've found to work around the problem is to set a single visible pixel in the 24x24 icon, make it black but give it an opacity of just 1 (out of 255). This will make it practically invisible and it should appear correctly on all background colours. Still, it's hackish so I'm wondering if there's a nicer solution. Any ideas?

I only need this to work on MSW, FWIW.

--
Best regards,
Andreas Falkenhahn mailto:and...@falkenhahn.com
shot0.png
shot1.png
shot2.png

Vadim Zeitlin

unread,
Sep 21, 2021, 10:45:23 AM9/21/21
to wx-u...@googlegroups.com
On Tue, 21 Sep 2021 15:35:42 +0200 Andreas Falkenhahn wrote:

AF> I have a wxListView with 7 columns. The second column contains text,
AF> all the other columns contain a 24x24 icon. Sometimes, however, I don't
AF> want the icon to be shown. Instead, the column should be empty. I'm
AF> having some difficulties getting this to work correctly because it
AF> looks like empty columns are automatically hidden.

I don't think this is correct, perhaps they're just auto-sized to 0?
If they really are hidden, I'd like to know how can this be reproduced
in the listctrl sample.

AF> I've tried the following to solve this issue:
AF>
AF> 1) Create a dummy 24x24 icon which is completely transparent. This
AF> doesn't work. For some reason, completely transparent icons are drawn
AF> as a 24x24 black rectangle. See shot1.png. I don't actually understand
AF> why this happens and this looks like a bug to me.

wxMSW doesn't support transparency except in a few well-defined places, so
I wouldn't be very surprised by this...

AF> 2) As a test to see why 1) doesn't work, I've made a single pixel
AF> visible in the 24x24 icon. Now it suddenly works correctly but of
AF> course it looks ugly because there's a random pixel now in the top-left
AF> corner of the column. See shot2.png.

... if this didn't happen. I admit I have no explanation about why does
transparency work with one not fully transparent pixel but not with all of
them being transparent, sorry.

AF> 3) Make the whole 24x24 icon opaque and white. This solves the problem
AF> but of course this won't look correctly if the listview's background
AF> colour isn't white.

Yes, this is what I would have done, except I'd use the current background
colour to create this icon dynamically.

AF> Still, it's hackish so I'm wondering if there's a nicer solution. Any
AF> ideas?

I don't think the empty column should be hidden at all. If it is,
hopefully this can be fixed, but first this would need to be reproduced.

Regards,
VZ

--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/

Andreas Falkenhahn

unread,
Sep 27, 2021, 12:32:22 PM9/27/21
to Vadim Zeitlin
On 21.09.2021 at 16:45 Vadim Zeitlin wrote:

> I don't think this is correct, perhaps they're just auto-sized to 0?
> If they really are hidden, I'd like to know how can this be reproduced
> in the listctrl sample.

Sorry, that was a false alarm. The cause of the problem was that I was
overriding GetItemWidthWithImage() and returning 0 in case there was
no icon. So it was a bug in my code.

> wxMSW doesn't support transparency except in a few well-defined places, so
> I wouldn't be very surprised by this...

Actually, alpha transparency works just fine in wxListView. All the images
I'm using in my wxListView use alpha channel transparency. The only thing
that doesn't work is if the image is 100% transparent. This could be a bug.
Check the attached demo source. A 24x24 image that is only partly transparent
is drawn fine, a 24x24 image that is fully transparent appears as a black
opaque rectangle for some reason.
test.png
test.cpp

Vadim Zeitlin

unread,
Sep 27, 2021, 12:57:17 PM9/27/21
to wx-u...@googlegroups.com
On Mon, 27 Sep 2021 18:32:28 +0200 Andreas Falkenhahn wrote:

AF> On 21.09.2021 at 16:45 Vadim Zeitlin wrote:
AF>
AF> > I don't think this is correct, perhaps they're just auto-sized to 0?
AF> > If they really are hidden, I'd like to know how can this be reproduced
AF> > in the listctrl sample.
AF>
AF> Sorry, that was a false alarm. The cause of the problem was that I was
AF> overriding GetItemWidthWithImage() and returning 0 in case there was
AF> no icon. So it was a bug in my code.

Thanks for confirming this.

AF> > wxMSW doesn't support transparency except in a few well-defined places, so
AF> > I wouldn't be very surprised by this...
AF>
AF> Actually, alpha transparency works just fine in wxListView. All the images
AF> I'm using in my wxListView use alpha channel transparency. The only thing
AF> that doesn't work is if the image is 100% transparent. This could be a bug.
AF> Check the attached demo source. A 24x24 image that is only partly transparent
AF> is drawn fine, a 24x24 image that is fully transparent appears as a black
AF> opaque rectangle for some reason.

Yes, as I wrote in the original reply, it looks like a bug, but I really
don't have time to look into it, sorry. If you can debug it (could it be
somehow related to pre-multiplication again?), it would be great, if not
we're just going to have to live with it for now.
Reply all
Reply to author
Forward
0 new messages