[英]C++ wxWidgets: Set Font After Widget Creation
So basically I found out that you can only set font before the widget creation or font won't change, but I need to change the font after element creation so how can I do it?所以基本上我发现你只能在创建小部件之前设置字体或字体不会改变,但我需要在创建元素后更改字体,我该怎么做呢?
void MyMain::makeBtnPanel()
{
btnPanel = new wxPanel(this, wxID_ANY);
wxGridSizer* grid = new wxGridSizer(5, 4, 2, 2);
// here is hidden code that is adding widgets to grid
btnPanel->SetSizer(grid);
sizer->Add(btnPanel, 5, wxEXPAND);
}
void MyMain::styleBtns()
{
wxFont mainBtnFont(
16,
wxFONTFAMILY_DEFAULT,
wxFONTSTYLE_NORMAL,
wxFONTWEIGHT_EXTRALIGHT
);
btnPanel->SetFont(mainBtnFont);
}
styleBtns
function is not working but if I set font immediately after btnPanel
creation (on 2nd line of makeBtnPanel
function) font will be set. styleBtns
function 不起作用,但如果我在创建btnPanel
后立即设置字体(在makeBtnPanel
函数的第二行),字体将被设置。
class constructor: class 构造函数:
MyMain::MyMain()
: wxFrame(
NULL,
wxID_ANY,
"Calculator",
wxDefaultPosition,
wxSize(322, 392)
)
{
sizer = new wxBoxSizer(wxVERTICAL);
SetSizer(sizer);
makeDisplayPanel();
makeBtnPanel();
styleBtns();
setupMainFrame();
}
Omg, I'm so dumb.天哪,我太笨了。 I couldn't change font because I was setting font to empty variables.
我无法更改字体,因为我将字体设置为空变量。 I wrote
else if
instead of if
and code didn't execute, it didn't set these variables.我写了
else if
而不是if
并且代码没有执行,它没有设置这些变量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.