Re: creating a custom button in GTK--



On Wed, Jan 12, 2005 at 14:43:21 +0100, Akos Maroy wrote:
> Hi,
> 
> A newbie question here: I'd like to create a custom button in GTK--. I 
> subclassed Gtk::Bin, which would contain the only child, shown inside 
> the button. I can draw the border of my button in the overrideen 
> on_expose_event() function. But what I can't do is to influence where 
> the child widget is drawn when calling Bin::on_expose_event() from 
> within the overriden on_expose_event().

Why don't you override Gtk::Button? You can completely change look with
overriding on_expose_event, but you would get the "clicked" signal for
free.

> I tried to override on_size_allocate, calculate the space available for 
> the child widget there (which is the size of my button, minus the size 
> of the borders which display it as a button). and then call 
> get_child()->size_allocate() with the calculated size - but this does 
> not have the desired effect.

What do you set to the x and y fileds of the allocation?

Since you are creating an active widget, it must have a window. Gtk::Bin
by itself does not allocate it. Have you done this? (Note: If you
subclass Gtk::Button, you would get that for free too).

The x and y passed in allocation to you is offset relative to whatever
parent widget uses for drawing (containers usualy use their ancestor's
one). But the offset passed to your child must be relative to your
window, which, as an active widget, you surely have allocated, right?

-------------------------------------------------------------------------------
						 Jan 'Bulb' Hudec <bulb ucw cz>

Attachment: signature.asc
Description: Digital signature



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]