How to set font for one of toolbutton in wxToolbar?

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
shawnee
Experienced Solver
Experienced Solver
Posts: 78
Joined: Tue Jan 16, 2018 1:05 am

How to set font for one of toolbutton in wxToolbar?

Post by shawnee »

Hi all,

I want to set different font for one of toolbutton in wxToolbar.
wxToolbar::SetFont() is not my desire, it will set the same font for all of toolbutton.

Code: Select all

                wxToolBarToolBase  * toolbutton = toolbar->FindById(toolid); assert(toolbutton != NULL);
                wxToolBarBase * toolsubwin = toolbutton->GetToolBar(); assert(toolsubwin != NULL);
                wxFont ft = toolsubwin->GetFont();
                ft.SetWeight(wxFONTWEIGHT_BOLD);
                toolsubwin->SetFont(ft);
unfortunately, all of toolbutton are bold font. :-(
How? Thanks!
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7477
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: How to set font for one of toolbutton in wxToolbar?

Post by ONEEYEMAN »

Hi,
Did you try:

Code: Select all

toolbutton->SetFont( ft );
Thank you.
shawnee
Experienced Solver
Experienced Solver
Posts: 78
Joined: Tue Jan 16, 2018 1:05 am

Re: How to set font for one of toolbutton in wxToolbar?

Post by shawnee »

ONEEYEMAN wrote:Hi,
Did you try:

Code: Select all

toolbutton->SetFont( ft );
Thank you.
no SetFont() member function for wxToolBarToolBase class. :-(
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7477
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: How to set font for one of toolbutton in wxToolbar?

Post by ONEEYEMAN »

Hi,
Are you trying it for the button or some other control?
Maybe you can cast it to the button and set the font this way?

Something like this:

Code: Select all

wxToolBarToolBase  * toolbutton = toolbar->FindById(toolid); assert(toolbutton != NULL);
if( toolbutton.IsButton() )
{
    wxButton *button = (wxButton *) toolbutton;
    if( button )
        button->SetFont( ft );
Thank you.
Kvaz1r
Super wx Problem Solver
Super wx Problem Solver
Posts: 357
Joined: Tue Jun 07, 2016 1:07 pm

Re: How to set font for one of toolbutton in wxToolbar?

Post by Kvaz1r »

Not sure is it really can to be done.

What about method GetControl/1?

Something like

Code: Select all

m_toolBar->FindControl(toolid)->SetFont(ft);
but with all necessary checkings(on NULL).

Though maybe it will work only for controls that was added via AddControl.
shawnee
Experienced Solver
Experienced Solver
Posts: 78
Joined: Tue Jan 16, 2018 1:05 am

Re: How to set font for one of toolbutton in wxToolbar?

Post by shawnee »

ONEEYEMAN wrote:Hi,
Are you trying it for the button or some other control?
Maybe you can cast it to the button and set the font this way?

Something like this:

Code: Select all

wxToolBarToolBase  * toolbutton = toolbar->FindById(toolid); assert(toolbutton != NULL);
if( toolbutton.IsButton() )
{
    wxButton *button = (wxButton *) toolbutton;
    if( button )
        button->SetFont( ft );
}
Thank you.
Can't do this, it got crash.
wxToolBarToolBase isn't inherited from wxButton, it just inherits from wxObject.
shawnee
Experienced Solver
Experienced Solver
Posts: 78
Joined: Tue Jan 16, 2018 1:05 am

Re: How to set font for one of toolbutton in wxToolbar?

Post by shawnee »

Kvaz1r wrote:Not sure is it really can to be done.

What about method GetControl/1?

Something like

Code: Select all

m_toolBar->FindControl(toolid)->SetFont(ft);
but with all necessary checkings(on NULL).

Though maybe it will work only for controls that was added via AddControl.
Yes, you are right. it will work only for controls that was added via AddControl. I' m using AddTool.
Thanks!
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7477
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: How to set font for one of toolbutton in wxToolbar?

Post by ONEEYEMAN »

Hi,
Even if it is possible on non-MSW platform on Windows it is not possible, since, at least on Windows you are working with the bitmap essentially creating the image list.

So, unless you want to modify every single bitmap, I suggest to use one font.

Thank you.
shawnee
Experienced Solver
Experienced Solver
Posts: 78
Joined: Tue Jan 16, 2018 1:05 am

Re: How to set font for one of toolbutton in wxToolbar?

Post by shawnee »

I thought out a trick way to show different(bold) font on a toolbutton.
That's render icon and bold font label into a bitmap together, then set this rendered bitmap as the bitmap of this toolbutton.

There are two difficult obstacles to me.
1. each of label has different length(but the lenght of string has limit, like 20). That means the width of bitmap from string is not fixed.
2. jiont a icon(width and height is fixed) with the label string bitmap, and If there is a gap between with icon and string bitmap should be great.

Anybody could give me some coding hints? Thanks.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7477
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: How to set font for one of toolbutton in wxToolbar?

Post by ONEEYEMAN »

Hi,
What if you try to add control to toolbar and use wxBitmapButton?

Thank you.
shawnee
Experienced Solver
Experienced Solver
Posts: 78
Joined: Tue Jan 16, 2018 1:05 am

Re: How to set font for one of toolbutton in wxToolbar?

Post by shawnee »

ONEEYEMAN wrote:Hi,
What if you try to add control to toolbar and use wxBitmapButton?

Thank you.
it's good idea, but how can I let wxButton as flat style just looks like toolbutton on wxToolBar?
User avatar
doublemax
Moderator
Moderator
Posts: 19158
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to set font for one of toolbutton in wxToolbar?

Post by doublemax »

You should also ask yourself if this all is worth the effort. It'll be an unusual GUI design element to say the least, i don't think i've ever seen this anywhere.
Use the source, Luke!
shawnee
Experienced Solver
Experienced Solver
Posts: 78
Joined: Tue Jan 16, 2018 1:05 am

Re: How to set font for one of toolbutton in wxToolbar?

Post by shawnee »

doublemax wrote:You should also ask yourself if this all is worth the effort. It'll be an unusual GUI design element to say the least, i don't think i've ever seen this anywhere.
Anyway, I still think it is strange there is no member function to set font for label of individual toolbutton.
User avatar
doublemax
Moderator
Moderator
Posts: 19158
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to set font for one of toolbutton in wxToolbar?

Post by doublemax »

Anyway, I still think it is strange there is no member function to set font for label of individual toolbutton.
At least under Windows the underlying native toolbar does not support that either. I don't know about other platforms.
Use the source, Luke!
Post Reply