wxIcon::SetHeight(), wxIcon::SetWidth() not Working

52 views
Skip to first unread message

Jason Liam

unread,
Jul 5, 2021, 12:28:09 PM7/5/21
to wx-u...@googlegroups.com
Hi i am showing a wxIcon onto a wxPanel. The icon is visible. But its dimensions are big w.r.t the panel. So I want to change its height and width. Upon looking into the documentation https://docs.wxwidgets.org/3.0/classwx_icon.html#a5c5d857cd6fda4ecc05ba4820d4aa2fe
I tried to use the SetHeight() method but it shows error which says expression must have class type.
This is how i create the wxIcon in the class declaration:
MyClass: public wxPane
{
wxIcon myIcon(wxIcon(samples_xmp);
}
And then inside the constructor i have :
MyClass::MyClass(....)
{
    myIcon.SetHeight();//this gives the above said error
}
I am using the xpm format to show the icon. How can i change the size of myIcon  to lets say 20 pixels wide and 20 pixels high? Should I use samples_xpm.SetHeight(20) instead? But this won't make sense since samples_xpm is not a class object. But if myIcon is a class object why aren't the SetHeight() and SetWidth() methods available? How can i change the height of myIcon.

PB

unread,
Jul 5, 2021, 1:24:36 PM7/5/21
to wx-users
According to the documentation in the master, wxIcon and wxBitmap cannot change the size, see also https://github.com/wxWidgets/wxWidgets/commit/26ee45e4a55270c79cbe0b691288d8d235626aca

I think the simplest method would be to convert the wxIcon to wxImage, use wxImage::Resize() and convert back to wxIcon, hoping you do not run into a transparency related bug. IIRC, few of those have been fixed in the master.

However, resizing a bitmap in any way likely means it will become ugly: either blurry or pixelated.

Jason Liam

unread,
Jul 5, 2021, 1:59:29 PM7/5/21
to wx-u...@googlegroups.com
I have a wxPanel and in it a wxStaticText and to the right of that wxStaticText i have an svg icon. The situation is shown in the screenshot below. My questions are:
1) Is it possible to use the svg and achieve the result shown in the screenshot below?
2) If it is possible to use an svg in wxWidgets, then can i change the size and colour of that svg by using some methods?
3) If there is no way to use svg, then how should I get the desired result? Or what is the best way of achieving this?

--
Please read https://www.wxwidgets.org/support/mlhowto.htm before posting.
---
You received this message because you are subscribed to the Google Groups "wx-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wx-users+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/wx-users/4d06ebbb-7fcc-4229-923b-d7abe834919dn%40googlegroups.com.
usingsvg.png

Gunter Königsmann

unread,
Jul 5, 2021, 2:53:02 PM7/5/21
to PB, wx-users
wxMaxima avoids blur in the following way:

- all icons are provided in two sizes: 192 and 256 pixels
- all other sizes wxMaxima used are generated by scaling one of them by an integer factor or 1/(an integer).
You won't get every imaginable size this way. But you always get a crisp icon near to the ideal size.
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.

PB

unread,
Jul 5, 2021, 2:59:51 PM7/5/21
to wx-users
On Monday, July 5, 2021 at 7:59:29 PM UTC+2 Jason Liam wrote:
2) If it is possible to use an svg in wxWidgets, then can i change the size and colour of that svg by using some methods

I believe wxWidgets cannot rasterize an SVG, it can only write it with wxSVGDC.

You could check the last two posts in this thread about using a simple 3d party code with no dependencies:
Reply all
Reply to author
Forward
0 new messages