Re: GtkDrawingArea initialization



> >How do I get a GtkDrawingArea to show some initial drawings when the GUI 
> >starts...???  Specifically, I want a 2x2 rectangle pre-drawn at the 
> >center of the DrawingArea so that when the program starts, you can 
> >immediately see this center point...  The problem is, I have inserted the 
> >drawing code in several places I think it would work (in a constructor -- 
> >using gtkmm), but when I run my program, the rectangle does not show up... 
> >Please help...
> 
> all drawing in an on-screen drawable (like your DrawingArea) in all X
> Window related toolkits (including GTK) happens when handling an
> expose event. in GTK, that means you have to connect to the "expose"
> signal emitted by the drawing area, and draw from within the function
> that handles the signal.
>
> there are *no* exceptions to this "rule". drawing anywhere other than
> in an expose handler is, at best, undefined in its effects.

So you should emit an "exopose_event" on your DrawingArea, there are
several ways to do it :
  g_signal_emit_by_name(darea, "expose_event");
  gtk_widget_queue_draw_area(darea, x, y, w, h);
but I prefer this one :
  gtk_widget_queue_draw(darea);

these calls will make your area use the callback you connected to,
you can do it at anytime when your DrawingArea is created but it will
be really drawn only when the DrawingArea is realized.
Please don't draw directly to your area, you will encounter problems
with GraphicContexts, Colormaps ...

Sinsedrix ;o)

------------------------------------------

Faites un voeu et puis Voila ! www.voila.fr 





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