Wxbutton label font resize

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
Emerald2240
Knows some wx things
Knows some wx things
Posts: 30
Joined: Tue Dec 11, 2018 1:38 pm

Wxbutton label font resize

Post by Emerald2240 » Fri Dec 14, 2018 8:11 pm

Hello!
I'm a newbie in wxwidgets! selftaught and teaching, I recently built a calculator app for calculating basic functions and some people complained about how small the labels/Display was.
So I managed to create a wxfont function to increase the size of my wxtextctrl display but I don't seem to be able to find any function relating to the change of the label of my buttons' size to something larger...
Forgive my naivety

User avatar
doublemax
Moderator
Moderator
Posts: 14300
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Wxbutton label font resize

Post by doublemax » Sat Dec 15, 2018 2:56 am

So I managed to create a wxfont function to increase the size of my wxtextctrl display
I'm not quite sure what you mean by that, but if you managed to set a bigger font for a text control, the same will work for buttons.

If you want a bigger font for all controls, set a bigger font for the parent of these controls *before* creating them. By that they will all inherit the bigger font.

Code: Select all

wxFont font = GetFont();                    // get the current font of, e.g. a wxFrame, depending on the context of this code
font.SetPixelSize( wxSize(0,24) );
SetFont( font );
// create child controls here...
Or you can set the new font for individual controls only:

Code: Select all

wxFont font = GetFont();                    // get the current font of, e.g. a wxFrame, depending on the context of this code
font.SetPixelSize( wxSize(0,24) );

wxButton *button = new wxButton(panel, wxID_ANY, "button one");
button->SetFont( font );
If you use sizers for the layout of the controls (what you should do), then the controls will automatically get sizes that are big enough for the font size.
Use the source, Luke!

Emerald2240
Knows some wx things
Knows some wx things
Posts: 30
Joined: Tue Dec 11, 2018 1:38 pm

Re: Wxbutton label font resize

Post by Emerald2240 » Sat Dec 15, 2018 4:26 pm

doublemax wrote:
So I managed to create a wxfont function to increase the size of my wxtextctrl display
I'm not quite sure what you mean by that, but if you managed to set a bigger font for a text control, the same will work for buttons.

If you want a bigger font for all controls, set a bigger font for the parent of these controls *before* creating them. By that they will all inherit the bigger font.

Code: Select all

wxFont font = GetFont();                    // get the current font of, e.g. a wxFrame, depending on the context of this code
font.SetPixelSize( wxSize(0,24) );
SetFont( font );
// create child controls here...
Or you can set the new font for individual controls only:

Code: Select all

wxFont font = GetFont();                    // get the current font of, e.g. a wxFrame, depending on the context of this code
font.SetPixelSize( wxSize(0,24) );

wxButton *button = new wxButton(panel, wxID_ANY, "button one");
button->SetFont( font );
If you use sizers for the layout of the controls (what you should do), then the controls will automatically get sizes that are big enough for the font size.
Thanks a lot! I just simply used the same layout I used to increase the font size of my wxtextctrl and replaced it with the button! it works! Though it needs me to click the button before the font actually changes, I'm working on this now!
Any ideas would be helpful! And by the way, I used code::blocks drag drop wxwidgets from scratch of my wxwidgets programming career so I have little to no experience with the actual coding process I'm also trying to work on that as well

User avatar
doublemax
Moderator
Moderator
Posts: 14300
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Wxbutton label font resize

Post by doublemax » Sat Dec 15, 2018 5:00 pm

Thanks a lot! I just simply used the same layout I used to increase the font size of my wxtextctrl and replaced it with the button! it works! Though it needs me to click the button before the font actually changes, I'm working on this now!
Any ideas would be helpful!
Please show some code, because i have absolutely no idea what you're doing.
Use the source, Luke!

Emerald2240
Knows some wx things
Knows some wx things
Posts: 30
Joined: Tue Dec 11, 2018 1:38 pm

Re: Wxbutton label font resize

Post by Emerald2240 » Tue Dec 18, 2018 10:32 pm

doublemax wrote:
Thanks a lot! I just simply used the same layout I used to increase the font size of my wxtextctrl and replaced it with the button! it works! Though it needs me to click the button before the font actually changes, I'm working on this now!
Any ideas would be helpful!
Please show some code, because i have absolutely no idea what you're doing.
sorry i took time pasting the code. here it is

Code: Select all

void projectcalciFrame::OnButton19Click(wxCommandEvent& event)
{

     wxFont font1 = Button1->GetFont();
    font1.SetPointSize(10);
    Button1->SetFont(font1);

    wxFont font2 = Button2->GetFont();
    font2.SetPointSize(10);
    Button2->SetFont(font2);

    wxFont font3 = Button3->GetFont();
    font3.SetPointSize(10);
    Button3->SetFont(font3);

    wxFont font4 = Button4->GetFont();
    font4.SetPointSize(10);
    Button4->SetFont(font4);

    wxFont font5 = Button5->GetFont();
    font5.SetPointSize(10);
    Button5->SetFont(font5);

    wxFont font6 = Button6->GetFont();
    font6.SetPointSize(10);
    Button6->SetFont(font6);

    wxFont font7 = Button7->GetFont();
    font7.SetPointSize(10);
    Button7->SetFont(font7);

    wxFont font8 = Button8->GetFont();
    font8.SetPointSize(10);
    Button8->SetFont(font8);

    wxFont font9 = Button9->GetFont();
    font9.SetPointSize(10);
    Button9->SetFont(font9);

    wxFont font10 = Button10->GetFont();
    font10.SetPointSize(10);
    Button10->SetFont(font10);

    wxFont font11 = Button11->GetFont();
    font11.SetPointSize(10);
    Button11->SetFont(font11);

    wxFont font12 = Button12->GetFont();
    font12.SetPointSize(10);
    Button12->SetFont(font12);

    wxFont font13 = Button13->GetFont();
    font13.SetPointSize(10);
    Button13->SetFont(font13);

    wxFont font14 = Button14->GetFont();
    font14.SetPointSize(10);
    Button14->SetFont(font14);

    wxFont font15 = Button15->GetFont();
    font15.SetPointSize(10);
    Button15->SetFont(font15);

    wxFont font16 = Button16->GetFont();
    font16.SetPointSize(10);
    Button16->SetFont(font16);

    wxFont font17 = Button17->GetFont();
    font17.SetPointSize(10);
    Button17->SetFont(font17);

}
i just simply created a button that increases the font of all butttons once clicked......
Last edited by doublemax on Wed Dec 19, 2018 1:03 am, edited 1 time in total.
Reason: Added code tags

User avatar
doublemax
Moderator
Moderator
Posts: 14300
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Wxbutton label font resize

Post by doublemax » Wed Dec 19, 2018 1:08 am

Thanks.

This is a little more complicated than it needs to be. The font you get from "Button1->GetFont()" is probably the same for all buttons, so you could just change the font size and then set this font for all buttons.

There is however the problem that the buttons won't automatically resize themselves according to the new font size.

The method i proposed earlier should be simpler: Just set a new (bigger) font for the parent window before creating the buttons and they should all inherit that font size.

If you're using a graphical GUI editor, maybe you can even set a bigger font size there??? (I don't know, because i don't use any GUI editor).
Use the source, Luke!

Emerald2240
Knows some wx things
Knows some wx things
Posts: 30
Joined: Tue Dec 11, 2018 1:38 pm

Re: Wxbutton label font resize

Post by Emerald2240 » Wed Dec 19, 2018 6:48 pm

doublemax wrote:Thanks.

This is a little more complicated than it needs to be. The font you get from "Button1->GetFont()" is probably the same for all buttons, so you could just change the font size and then set this font for all buttons.

There is however the problem that the buttons won't automatically resize themselves according to the new font size.

The method i proposed earlier should be simpler: Just set a new (bigger) font for the parent window before creating the buttons and they should all inherit that font size.

If you're using a graphical GUI editor, maybe you can even set a bigger font size there??? (I don't know, because i don't use any GUI editor).
thanks a lot for your reply and advice, like i hinted much earlier i use code::blocks' drag n drop wxwidgets editor to create my projects and i'm a hardcore beginner still figuring my own way around so i sincerely plead for your patience with me!!!

Post Reply