how to set font and size for my program? Topic is solved

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
Owyn
Earned a small fee
Earned a small fee
Posts: 17
Joined: Thu Jul 01, 2010 2:23 pm

how to set font and size for my program?

Post by Owyn » Sat Sep 04, 2010 9:56 am

becouse it uses system size and font and on systems with big fonts GUI becomes a mess :roll:
VC++ 2008

jfouche
Super wx Problem Solver
Super wx Problem Solver
Posts: 442
Joined: Tue May 06, 2008 4:52 pm
Location: France

Post by jfouche » Sat Sep 04, 2010 10:11 am

Each graphical control (text control, combo box, frame, ...) inherit from wxWindow. This class contains a SetFont method. You just have to create your wxFont and applied it :

Code: Select all

wxFont myFont(12, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD);
myWindow->SetFont(myFont);
Jérémie

Owyn
Earned a small fee
Earned a small fee
Posts: 17
Joined: Thu Jul 01, 2010 2:23 pm

Post by Owyn » Sat Sep 04, 2010 10:29 am

doesn't work =\

Code: Select all

bool MyApp::OnInit()
{
    if ( !wxApp::OnInit() )
        return false;
	setlocale( LC_NUMERIC, "English" );
	MyFrame *frame = new MyFrame(NULL, _T("My Programs title"), 350, 350, 500, 400);

    wxFont myFont(12, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD);
    frame->SetFont(myFont);

    frame->Show(true);
    return true;
}
- doesn't change anything

and if i place it in frame constructor MyFrame::MyFrame() it crashes
VC++ 2008

jfouche
Super wx Problem Solver
Super wx Problem Solver
Posts: 442
Joined: Tue May 06, 2008 4:52 pm
Location: France

Post by jfouche » Sat Sep 04, 2010 12:08 pm

What does contain your frame ?
Do you draw inside ? If you draw with a DC, the documentation tolds you the given font will not be used. You must use wxDC::SetFont() instead.
I suggest you to try with a simple wxStaticText in your frame, and see if it's OK. If not, post some code.
Jérémie

Owyn
Earned a small fee
Earned a small fee
Posts: 17
Joined: Thu Jul 01, 2010 2:23 pm

Post by Owyn » Sat Sep 04, 2010 1:40 pm

jfouche wrote:What does contain your frame ?
Do you draw inside ? If you draw with a DC, the documentation tolds you the given font will not be used. You must use wxDC::SetFont() instead.
I suggest you to try with a simple wxStaticText in your frame, and see if it's OK. If not, post some code.
how do you use wxDC::SetFont() ? i gives me error "illegal call of non-static member function"

and my frame do not draw, just a panel with text and checkboxes

Code: Select all

MyFrame::MyFrame(wxFrame *frame, wxChar * title, int x, int y, int w, int h)
       : wxFrame(frame, wxID_ANY, title, wxPoint(x, y), wxSize(w, h))
{
	Connect(wxEVT_CLOSE_WINDOW, wxCloseEventHandler(Veto::OnClose));

    SetIcon(wxICON(sample));

    wxMenu *fileMenu = new wxMenu;
    wxMenu *helpMenu = new wxMenu;

    helpMenu->Append(Minimal_About, "&About...\tF1", "Show about dialog");
    fileMenu->Append(Minimal_Quit, "E&xit\tAlt-X", "Quit this program");
    wxMenuBar *menuBar = new wxMenuBar();
    menuBar->Append(fileMenu, "&File");
    menuBar->Append(helpMenu, "&Help");
    SetMenuBar(menuBar);

    CreateStatusBar(2);
    SetStatusText("Status!");

    wxPanel *panel = new wxPanel(this, wxID_ANY, wxPoint(0, 0), wxSize(400, 200), wxTAB_TRAVERSAL);

    wxCheckBox box_box = new wxCheckBox( panel, ID_SEEDER, wxT("my checkbox"), wxPoint(100, 100), wxDefaultSize, 0 );
    ...
VC++ 2008

jfouche
Super wx Problem Solver
Super wx Problem Solver
Posts: 442
Joined: Tue May 06, 2008 4:52 pm
Location: France

Post by jfouche » Sat Sep 04, 2010 2:09 pm

Does your close event works ? I suggest you to do :

Code: Select all

Connect(wxEVT_CLOSE_WINDOW, wxCloseEventHandler(MyFrame::OnClose), NULL, this);

...

void MyFrame::OnClose(wxCloseEvent& event)
{
   Destroy();
}
For your pb, does the following code works ?

Code: Select all

box_box->SetFont(myFont); // As defined before
For the wxDC::SetFont(...), it's usefull if you manage the paint event (but it's not the case for you). You must create a DC and call the SetFont method on the created DC (but as I said, do not use it if you don't need to paint).
Jérémie

Owyn
Earned a small fee
Earned a small fee
Posts: 17
Joined: Thu Jul 01, 2010 2:23 pm

Post by Owyn » Sat Sep 04, 2010 3:17 pm

Does your close event works ?
Yes.

Code: Select all

box_box->SetFont(myFont);
worked.

and i finally found a way, i did ->SetFont on the panel

panel->SetFont(MyFont);
VC++ 2008

jfouche
Super wx Problem Solver
Super wx Problem Solver
Posts: 442
Joined: Tue May 06, 2008 4:52 pm
Location: France

Post by jfouche » Sat Sep 04, 2010 3:21 pm

Next time, accept the post that helped you, not your own.
Jérémie

Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria » Sat Sep 04, 2010 5:30 pm

jfouche wrote:Next time, accept the post that helped you, not your own.
Fixed :)
"Keyboard not detected. Press F1 to continue"
-- Windows

Post Reply