Re: [API 2.4] font in entry
- From: Kjell Ahlstedt <kjell ahlstedt bredband net>
- To: Yann Leydier <yann leydier info>
- Cc: gtkmm-list gnome org
- Subject: Re: [API 2.4] font in entry
- Date: Wed, 07 Nov 2012 18:23:28 +0100
I started from the entry/simple example in the gtkmm tutorial,
http://git.gnome.org/browse/gtkmm-documentation/tree/examples/book/entry/simple,
and added
class MyEntry : public Gtk::Entry
{
public:
MyEntry();
protected:
//Signal handlers.
void on_my_map();
};
#define SET_FONT_IN_CONSTRUCTOR 1
MyEntry::MyEntry()
{
#if SET_FONT_IN_CONSTRUCTOR
std::cout << "Setting font in constructor" << std::endl;
Pango::FontDescription fd(get_style_context()->get_font());
fd.set_family("times");
fd.set_style(Pango::STYLE_ITALIC);
override_font(fd);
#endif
signal_map().connect(sigc::mem_fun(*this, &MyEntry::on_my_map));
}
void MyEntry::on_my_map()
{
#if !SET_FONT_IN_CONSTRUCTOR
std::cout << "Setting font in on_my_map()" << std::endl;
Pango::FontDescription fd(get_style_context()->get_font());
fd.set_family("times");
fd.set_style(Pango::STYLE_ITALIC);
override_font(fd);
#endif
}
It sets the font either in the constructor or in the map signal handler.
Both alternatives work.
This is gtkmm 3. If you need code for gtkmm 2, and you can't figure out
yourself how to change my code for gtkmm 2, I can probably help you with
that.
Kjell
2012-11-07 11:10, Yann Leydier skrev:
Here is some information to add to the subject: connecting my function
to signal size-request or size-allocate works when the signal is
called for the second time.
This solution is unsatisfying as the signal is emitted quite often and
it isn't easy to disconnect the signal only when not needed anymore.
yann
On 07/11/12 09:33, Yann Leydier wrote:
Connecting the realize signal does not work any better than map and
map-event. :o(
According to this page, the realize signal is emitted even before map :
http://blog.yorba.org/jim/2010/10/those-realize-map-widget-signals.html
Other ideas?
Thanks,
yann
On 06/11/12 21:32, José Alburquerque wrote:
On Tue, 2012-11-06 at 18:09 +0100, Yann Leydier wrote:
Hullo,
I'm trying to change the font (face and style) in a custom object
derived from Entry.
I use the following code:
Pango::FontDescription
fd(get_layout()->get_context()->get_font_description());
if (word.HasSerif())
fd.set_family("times");
else
fd.set_family("arial");
if (word.IsItalics())
fd.set_style(Pango::STYLE_ITALIC);
else
fd.set_style(Pango::STYLE_NORMAL);
get_layout()->get_context()->set_font_description(fd);
This seems to need the widget to be associated to a fully functionnal
GdkWidow, so rather than putting this code in the constructor, I
connected it to a signal.
I tried map and map-event but it did not work. I thought that these
signals where emitted when (resp.) asking to associate and associating
the widget to a GdkWindow…
I also tried expose-event, which is supposed to be emitted when the
widget is rendered, and it changes the font only when the edit gets
the
focus! O_O
Do you have any insight on the matter, please?
You can use the Gtk::Widget::signal_realize(). When it is emitted, the
Gdk::Window associated with the widget should be fully functional.
yann
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]