Re: font size gtk_*_new_with_label
- From: "Garth's KidStuff" <garthskidstuff gmail com>
- To: ariel_xxii yahoo com ar
- Cc: gtk-app-devel-list gnome org
- Subject: Re: font size gtk_*_new_with_label
- Date: Sun, 13 Jul 2008 09:25:53 -0700
I'm using
gtk_widget_modify_font() and
style = gtk_rc_style_new();
pango_font_description_free( style->font_desc );
style->font_desc = pfont;
gtk_widget_modify_style( widget, style );
to change the font size of my labels, but I can't do it on created
buttons with gtk_*_new_with_label() and neither in my statusbar.
I couldn't find any example on the net. I understand that I dont have the
reference to the labels... , but when gtk refresh > the screen needs the
reference to the labels...
So how to get the reference pointer or directly how to change the font size
on these objects ?
I have custom labels with my widgets...
Now, I'd rather change as less as possible the Glade code (Glade use
_with_label in generation code).
I think that would be better using with_label than a custom button (I'm not
completetly sure about it on gtk).
Could any body give me some help about this problem? I need to solve it
Thanks in advance, Regards
Luis
I wrote a short gtkmm method to scale the fontsize of various controls.
It's not complete (e.g. it doesn't do comboboxes, or entry widgets), but it
may answer your question.
ScaleWidgetFont(
Gtk::Widget* pCtrl, // [in] Control to shrink the text of
real scale) // [in] scale factor (should be < 1.0 to shrink control)
{
// Different kinds of controls need different sub-objects' font resized
Gtk::Frame* pFrame = dynamic_cast<Gtk::Frame*>(pCtrl);
if (NULL != pFrame) // e.g. Frames have label widgets they use to
display their text
pCtrl = pFrame->get_label_widget();
else
{ // ...and radio buttons and check buttons are simply containers with a
single label child
Gtk::Bin* pBin = dynamic_cast<Gtk::Bin*>(pCtrl);
if (NULL != pBin)
pCtrl = pBin->get_child();
}
Gtk::Label* pLabel = dynamic_cast<Gtk::Label*>(pCtrl);
if (NULL != pLabel)
{ // If we have a label we can set its font
Glib::RefPtr<Pango::Context> pPangoContext =
pLabel->get_pango_context();
Pango::FontDescription fontD =
pPangoContext->get_font_description();
fontD.set_size((int)(scale * fontD.get_size()));
pLabel->modify_font(fontD);
}
}
Cheers
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]