简体   繁体   中英

How can i set text size in wxWidgets?

Compiled application

I want to make the Hello World text bigger, but i can't figure out how

I tried using staticText1->SetSize(32) , staticText1->SetSize(wxSize(32,32)) and replacing wxDefaultSize with wxSize(32, 32) , but nothing works (I am not getting errors, it just doesnt change the text size)

This is my current code:

#include <wx/wx.h>

class Frame : public wxFrame
{
    private:
        wxStaticText* staticText1 = new wxStaticText(this, wxID_ANY, "Hello, World!", wxDefaultPosition, wxDefaultSize, wxALIGN_CENTER);
    public:
        Frame() : wxFrame(nullptr, wxID_ANY, "spageta", wxDefaultPosition, wxSize(400, 200)) {
            staticText1->SetForegroundColour(wxTheColourDatabase->Find("Black"));
        }
};

class App : public wxApp
{
public:
    App();
private:
    wxFrame* NewFrame = nullptr;    
public:
    virtual bool OnInit();
};

App::App()
{

}

bool App::OnInit()
{
    NewFrame = new Frame();
    NewFrame->Show(true);
    return true;
}

wxIMPLEMENT_APP(App);

You need to change the font size and not the window size. The best way to do it is to change the size of the same font it already uses, eg window->SetFont(window->GetFont().Scale(1.5)) , which would make the font 1.5 times bigger. The same approach can be used to make it bold, or italic etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM