简体   繁体   中英

code::blocks wxWidgets Changing the font of a wxStaticBoxSizer

I know that our questions put on evidence our knowledge, so be gentle please :). This is one of mine in C++. Well, here we go.

I'm trying to change from codeblocks the font of a StaticBoxSizer. I can change the font of the wxStaticBox in the properties section but I'm having a hard time finding a way to access the same thing for the wxStaticBoxSizer FROM wxSmith in codeBlocks.

I tried without success to acces the staticBox within the sizer. What's worst, i dont know how to access any of the wxSmith's elements from the code editor.

All hints are welcomed and thank you in advance.

Edit: I know for sure that there's nothing wrong with the IDE but here's the header and here the cpp .

I noticed that the sizers are not declared in the headers but in the constructor's implementation of the dialog. I try to access the sizer in the constructor but to no avail.

The links works to me but here are the contents of the files directly. I simplified the code to include the minimum of elements.

header:

/***************************************************************
 * Name:      sizerTestMain.h
 * Purpose:   Defines Application Frame
 * Author:    RainMaker ()
 * Created:   2015-11-11
 * Copyright: RainMaker ()
 * License:
 **************************************************************/

#ifndef SIZERTESTMAIN_H
#define SIZERTESTMAIN_H

//(*Headers(sizerTestFrame)
#include <wx/sizer.h>
#include <wx/menu.h>
#include <wx/button.h>
#include <wx/frame.h>
#include <wx/statusbr.h>
//*)

class sizerTestFrame: public wxFrame
{
    public:

        sizerTestFrame(wxWindow* parent,wxWindowID id = -1);
        virtual ~sizerTestFrame();

    private:

        //(*Handlers(sizerTestFrame)
        void OnQuit(wxCommandEvent& event);
        void OnAbout(wxCommandEvent& event);
        void OnButton1Click(wxCommandEvent& event);
        void OnButton3Click(wxCommandEvent& event);
        //*)

        //(*Identifiers(sizerTestFrame)
        static const long ID_BUTTON1;
        static const long ID_BUTTON2;
        static const long ID_BUTTON3;
        static const long idMenuQuit;
        static const long idMenuAbout;
        static const long ID_STATUSBAR1;
        //*)

        //(*Declarations(sizerTestFrame)
        wxButton* Button1;
        wxButton* Button2;
        wxButton* Button3;
        wxStatusBar* StatusBar1;
        //*)

        DECLARE_EVENT_TABLE()
};

#endif // SIZERTESTMAIN_H

and this is the cpp

/***************************************************************
 * Name:      sizerTestMain.cpp
 * Purpose:   Code for Application Frame
 * Author:    RainMaker ()
 * Created:   2015-11-11
 * Copyright: RainMaker ()
 * License:
 **************************************************************/

#include "wx_pch.h"
#include "sizerTestMain.h"
#include <wx/msgdlg.h>

//(*InternalHeaders(sizerTestFrame)
#include <wx/intl.h>
#include <wx/string.h>
//*)

//helper functions
enum wxbuildinfoformat {
    short_f, long_f };

wxString wxbuildinfo(wxbuildinfoformat format)
{
    wxString wxbuild(wxVERSION_STRING);

    if (format == long_f )
    {
#if defined(__WXMSW__)
        wxbuild << _T("-Windows");
#elif defined(__UNIX__)
        wxbuild << _T("-Linux");
#endif

#if wxUSE_UNICODE
        wxbuild << _T("-Unicode build");
#else
        wxbuild << _T("-ANSI build");
#endif // wxUSE_UNICODE
    }

    return wxbuild;
}

//(*IdInit(sizerTestFrame)
const long sizerTestFrame::ID_BUTTON1 = wxNewId();
const long sizerTestFrame::ID_BUTTON2 = wxNewId();
const long sizerTestFrame::ID_BUTTON3 = wxNewId();
const long sizerTestFrame::idMenuQuit = wxNewId();
const long sizerTestFrame::idMenuAbout = wxNewId();
const long sizerTestFrame::ID_STATUSBAR1 = wxNewId();
//*)

BEGIN_EVENT_TABLE(sizerTestFrame,wxFrame)
    //(*EventTable(sizerTestFrame)
    //*)
END_EVENT_TABLE()

sizerTestFrame::sizerTestFrame(wxWindow* parent,wxWindowID id)
{
    //(*Initialize(sizerTestFrame)
    wxMenuItem* MenuItem2;
    wxMenuItem* MenuItem1;
    wxMenu* Menu1;
    wxStaticBoxSizer* theSizer;
    wxMenuBar* MenuBar1;
    wxFlexGridSizer* FlexGridSizer1;
    wxMenu* Menu2;

    Create(parent, id, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE, _T("id"));
    FlexGridSizer1 = new wxFlexGridSizer(0, 3, 0, 0);
    theSizer = new wxStaticBoxSizer(wxHORIZONTAL, this, _("I want to change this title"));
    Button1 = new wxButton(this, ID_BUTTON1, _("with this"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON1"));
    theSizer->Add(Button1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    Button2 = new wxButton(this, ID_BUTTON2, _("or this"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON2"));
    theSizer->Add(Button2, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    FlexGridSizer1->Add(theSizer, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    Button3 = new wxButton(this, ID_BUTTON3, _("Or this"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON3"));
    FlexGridSizer1->Add(Button3, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    SetSizer(FlexGridSizer1);
    MenuBar1 = new wxMenuBar();
    Menu1 = new wxMenu();
    MenuItem1 = new wxMenuItem(Menu1, idMenuQuit, _("Quit\tAlt-F4"), _("Quit the application"), wxITEM_NORMAL);
    Menu1->Append(MenuItem1);
    MenuBar1->Append(Menu1, _("&File"));
    Menu2 = new wxMenu();
    MenuItem2 = new wxMenuItem(Menu2, idMenuAbout, _("About\tF1"), _("Show info about this application"), wxITEM_NORMAL);
    Menu2->Append(MenuItem2);
    MenuBar1->Append(Menu2, _("Help"));
    SetMenuBar(MenuBar1);
    StatusBar1 = new wxStatusBar(this, ID_STATUSBAR1, 0, _T("ID_STATUSBAR1"));
    int __wxStatusBarWidths_1[1] = { -1 };
    int __wxStatusBarStyles_1[1] = { wxSB_NORMAL };
    StatusBar1->SetFieldsCount(1,__wxStatusBarWidths_1);
    StatusBar1->SetStatusStyles(1,__wxStatusBarStyles_1);
    SetStatusBar(StatusBar1);
    FlexGridSizer1->Fit(this);
    FlexGridSizer1->SetSizeHints(this);

    Connect(ID_BUTTON1,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&sizerTestFrame::OnButton1Click);
    Connect(ID_BUTTON3,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&sizerTestFrame::OnButton3Click);
    Connect(idMenuQuit,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&sizerTestFrame::OnQuit);
    Connect(idMenuAbout,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&sizerTestFrame::OnAbout);
    //*)
}

sizerTestFrame::~sizerTestFrame()
{
    //(*Destroy(sizerTestFrame)
    //*)
}

void sizerTestFrame::OnQuit(wxCommandEvent& event)
{
    Close();
}

void sizerTestFrame::OnAbout(wxCommandEvent& event)
{
    wxString msg = wxbuildinfo(long_f);
    wxMessageBox(msg, _("Welcome to..."));
}

void sizerTestFrame::OnButton1Click(wxCommandEvent& event)
{
}

void sizerTestFrame::OnButton3Click(wxCommandEvent& event)
{

}

I solved my problem ! ! This is what did.

1 - I noticed that the sizer was not included in the header so I looked for the ways to include it from wxSmith. The magic came from the "isMember" checkBox in the properties table. It seems that this is the way of including it to the header and then accessing it.

2 - I created a member function at the end of the constructor:

void IbDialogue::setFonts();

3 - In the function implementation, I accessed the wxStaticBox of the wxStaticBoxSizer and set it like this:

wxFont* nf = new wxFont;
StaticBoxSizer7->GetStaticBox()->SetFont(nf->Bold());

And VOILÀ the font is mastered ! ! !

for (int i=0; i<1000000; i++)
cout<<(HA HA HA HA);

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