Any way to set font for Window and its children? Topic is solved
Any way to set font for Window and its children?
I was wondering if there is a way to sent a font for say a panel and have it propogate down to its children?
I'm working with a cross-platform app (Windows,Mac) and I need to be able to set basically a global font but i'd settle for the ability to set a font for a wxPanel and have its children change to that font.
thanks,
Chris Hodges
I'm working with a cross-platform app (Windows,Mac) and I need to be able to set basically a global font but i'd settle for the ability to set a font for a wxPanel and have its children change to that font.
thanks,
Chris Hodges
Did you took a look at the docs? wxWindow::SetFont
Visual C++ 9.0 / Windows XP Pro SP3 / wxWidgets 2.9.0 (SVN) | Colligere
-
- Filthy Rich wx Solver
- Posts: 203
- Joined: Tue Aug 31, 2004 7:06 pm
- Location: Behind a can of Mountain Dew
- Contact:
Something like this will probably do the trick:
I can't remember if wxWindowList is the correct name for what GetChildren returns but thats the essential logic.
Code: Select all
std::stack<wxWindow*> window_stack;
window_stack.push(parent_window);
while(!window_stack.empty())
{
wxWindow* current = window_stack.top();
window_stack.pop();
current->SetFont(font);
wxWindowList list = parent_window.GetChildren();
for(WindowList::Node *node = list.GetFirst(); node; node = node->GetNext())
window_stack.push(node->GetData());
}
-
- Filthy Rich wx Solver
- Posts: 203
- Joined: Tue Aug 31, 2004 7:06 pm
- Location: Behind a can of Mountain Dew
- Contact:
Oh, forgot to mention that is only if you want to do it after the parent window and children have been created. If you SetFont() (like vdell said) before you create the children, they will inherit the font. Someone correct me if I'm wrong on this (I've always assumed this is what the docs where trying to say but the whole property inheritance is a bit confusing).
Yes I did look at that but it does not seem to work at all under wxMAC. here's an example of what I tried.
wPanel *mainPanel = new wxPanel(this);
wxFont ff = mainPanel->GetFont();
ff->SetPointSize(24); // something way too large -- for testing
mainPanel->SetFont(ff);
wxPanel *subPanel = new wxPanel(mainPanel,-1);
wxTextCtrl *textCtrl = new wxTextCtrl(subPanel,-1 ........
The textCtrl is not changed to use the new larger font so then I tried inserting this after the creates of each.....
subPanel->InheritAttributes();
textCtrl->InheritAttributes();
And nothing.... still doesn't take. Now I've only tested this code on the Mac - maybe its a platform thing.
Chris Hodges
wPanel *mainPanel = new wxPanel(this);
wxFont ff = mainPanel->GetFont();
ff->SetPointSize(24); // something way too large -- for testing
mainPanel->SetFont(ff);
wxPanel *subPanel = new wxPanel(mainPanel,-1);
wxTextCtrl *textCtrl = new wxTextCtrl(subPanel,-1 ........
The textCtrl is not changed to use the new larger font so then I tried inserting this after the creates of each.....
subPanel->InheritAttributes();
textCtrl->InheritAttributes();
And nothing.... still doesn't take. Now I've only tested this code on the Mac - maybe its a platform thing.
Chris Hodges
eco wrote:Oh, forgot to mention that is only if you want to do it after the parent window and children have been created. If you SetFont() (like vdell said) before you create the children, they will inherit the font. Someone correct me if I'm wrong on this (I've always assumed this is what the docs where trying to say but the whole property inheritance is a bit confusing).
Just an idea, but have you tried to create all controls first and then call SetFont from the parent?cd_hodges wrote:Yes I did look at that but it does not seem to work at all under wxMAC. here's an example of what I tried.
wPanel *mainPanel = new wxPanel(this);
wxFont ff = mainPanel->GetFont();
ff->SetPointSize(24); // something way too large -- for testing
mainPanel->SetFont(ff);
wxPanel *subPanel = new wxPanel(mainPanel,-1);
wxTextCtrl *textCtrl = new wxTextCtrl(subPanel,-1 ........
The textCtrl is not changed to use the new larger font so then I tried inserting this after the creates of each.....
subPanel->InheritAttributes();
textCtrl->InheritAttributes();
And nothing.... still doesn't take. Now I've only tested this code on the Mac - maybe its a platform thing.
Chris Hodges
eco wrote:Oh, forgot to mention that is only if you want to do it after the parent window and children have been created. If you SetFont() (like vdell said) before you create the children, they will inherit the font. Someone correct me if I'm wrong on this (I've always assumed this is what the docs where trying to say but the whole property inheritance is a bit confusing).
Visual C++ 9.0 / Windows XP Pro SP3 / wxWidgets 2.9.0 (SVN) | Colligere