tags:

views:

18

answers:

2

I currently load a DrawingArea widget inside a Frame - and it always expands to fill the frame. I can then set the configure event on the DrawingArea to allocate a pixmap of the same size as the window, draw on it, then draw the pixmap to the DrawingArea (using draw_drawable).

However, now I want to overlay invisible widgets ontop of the DrawingArea - in order to create tooltip events for parts of the image displayed. So I tried to put the DrawingArea inside a Fixed instead - but now it does not expand to fill the window. I can give the DrawingArea an explicit size request - however I would really like it to expand to fill whatever space allocation it's parent window has been given. I have tried setting the size request to -1, but that does not help any.

Any suggestions?

A: 

Came up with a solution that sort of works:

  • Create a Fixed.
  • Create a DrawingArea and add it to Fixed.
  • Connect Fixed to 'size_allocate' signal, and in the signal handler, get the Fixed allocation (width and height), then get the DrawingArea to make a size_request of the current allocation.

It appears to do what I want, however I noticed now that two "size_allocate" signals are sent to fixed - one when the window is resized, and another presumably when the DrawingArea requests a new size allocation. To avoid doing a lot of extra unnecessary work in the second signal, I just return if the previous height/width match the new allocation. But I would rather do away with the second signal if possible.

I tried blocking/unblocking the size_allocate signal before/after the DrawingArea size_request to no avail (maybe because I am already inside the size_allocation handler).

Anyone know of a cleaner way to deal with this?

megamic
Yes, a cleaner way would be to skip the Fixed, and connect to the DrawingArea's "query-tooltip" signal. This allows you to decide what tooltip to show based on the coordinates of the mouse pointer.
ptomato
Thanks! Ill look into that.
megamic
+1  A: 

It sounds like you're jumping through a lot of hoops to avoid just implementing a custom widget. It might be worth your time to just learn to do that; override size request/allocate to get the size you want, override expose_event to draw your image, and override motion_notify_event or whatever other event handlers to handle mouse position and clicks.

Havoc P
Shows how much I know, I though I *was* writing a custom widget by doing it this way! Ideally I would not rather have to deal with mouse position directly - using a Fixed I can overlay invisible event boxes that will say generate tooltip events when the mouse hovers over a marker I draw on the Pixmap. I will do some reading on building custom widgets in any case...thanks.
megamic
DrawingArea is kind of a hacky thing to let you avoid subclassing to write a new widget just to draw some stuff. But, it's one of those shortcuts that bites you if you start doing anything complicated.
Havoc P