【问题标题】:code::blocks wxWidgets Changing the font of a wxStaticBoxSizercode::blocks wxWidgets 改变 wxStaticBoxSizer 的字体
【发布时间】:2015-11-11 15:38:21
【问题描述】:

我知道我们的问题证明了我们的知识,所以请保持温和 :)。这是我的 C++ 之一。好了,我们开始吧。

我正在尝试从代码块中更改 StaticBoxSizer 的字体。我可以在属性部分更改 wxStaticBox 的字体,但我很难找到一种方法来访问 codeBlocks 中的 wxStaticBoxSizer FROM wxSmith 的相同内容。

我尝试访问 sizer 中的 staticBox,但没有成功。最糟糕的是,我不知道如何从代码编辑器访问 wxSmith 的任何元素。

欢迎所有提示,并提前感谢您。

编辑: 我确信 IDE 没有任何问题,但这里是 header,这里是 cpp

我注意到,sizer 没有在标题中声明,而是在对话框的构造函数实现中声明。我尝试在构造函数中访问 sizer 但无济于事。

这些链接对我有用,但这里是文件的直接内容。我简化了代码以包含最少的元素。

标题:

/***************************************************************
 * 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

这是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)
{

}

【问题讨论】:

  • 向我们展示代码; 将 sn-p 粘贴到您的问题中。我不认为您的问题出在 codeBlocks IDE 上,而是出在您的代码上。
  • 我编辑了问题以添加文件。顺便说一句,这是一个快速的反应。
  • 抱歉,您没有将 sn-p 粘贴到您的问题中,而是粘贴了链接。再试一次,突出显示您的代码、复制到剪贴板、编辑您的问题并粘贴剪贴板中的代码并不难。
  • 这听起来很像您试图设置一张纸的字体和大小,显然,这是无法做到的。相反,将字体信息分配给页面上的字符串。由于 sizer 实际上不包含文本,但可能包含包含文本的对象,因此我将考虑设置 their 字体(而不是包含它们的父字体。快速使用该工具我的记忆似乎恢复了 - 设置元素的大小,而不是容器。另外,你可能更喜欢 wxFormBuilder 我多年前尝试过,从未回头看 C::B 包含的 WX“玩具”。
  • 感谢您的提示 enhzflep。这很有意义,也是我开始尝试做的。在阅读 wx 文档后,我得出了更改 sizer 字体的结论。我真的很想使用 wxFormBuilder,但到目前为止我喜欢 wxSmith。如果我发现工具而不是用户有问题,wxFormBuilder 将是我的下一个选择。

标签: c++ codeblocks wxwidgets


【解决方案1】:

我解决了我的问题! ! 就是这样。

1 - 我注意到 sizer 没有包含在标题中,所以我从 wxSmith 寻找包含它的方法。 魔力来自于属性表中的“isMember”复选框。看来这就是将它包含到标题中然后访问它的方式。

2 - 我在构造函数的末尾创建了一个成员函数:

void IbDialogue::setFonts();

3 - 在函数实现中,我访问了 wxStaticBoxSizer 的 wxStaticBox 并设置如下:

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

VOILÀ 字体被掌握了! ! !

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-12-07
    • 2012-06-30
    • 2020-05-16
    • 2013-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-14
    相关资源
    最近更新 更多