4

1、I have looked up many references about drawing a rectangle in GtkWindow in Gtk,but lots of them are used GtkDrawingArea . I want to know that can I draw a rectangle in GtkWindow directly without GtkDrawingArea?And if i can do this ,how should i do? Is there any examples or references?

2、Actually, I need to draw a rectangle in a gtkwindow ,and then add two buttons in the rectangle and specify coordinates of the point set to the fixed color value in a small field in the rectangle. I have tried the way of drawing rectangle by GtkDrawingArea,but GtkDrawingArea isn't a GTK_CONTAINER ,so I can't add anything in GtkDrawingArea;I also tried to use some Layout managers such as gtk_vbox ,but it seems failed. I can't place a button in the area of the rectangle.

Now I am confused how to do next.If someone can give me some guide or reference ,Thank you for much!

1 Answer 1

2

Yes, you can. You may need to set the "app-paintable" flag on the GtkWindow, but you can connect to its draw signal, and draw on the background with Cairo. Then return FALSE from the draw signal handler to signify that other handlers should still be invoked for the drawing; then the buttons can still be drawn on top. I don't know of any online examples for drawing directly on the window, though.

3
  • Thank you very much!As you said,I have done this with setting the "app-paintable" flag.But it seems that the drawing operation must be done in the draw signal handler.Now I need to show an image on a small field in the rectangle which i drawed directly above by setting the colour value of the points which specified by coordinates. So I must draw on the small field frequenty.I know I have two methods:
    – Jason
    Jul 23, 2013 at 16:22
  • 1、connect different draw signal handers to do this . But First ,I am not sure weather I can do like this ,and if I can ,how gtk will done with many signal handlers; 2、Manually emit the draw signal when i need to redraw.If this method is avaliable,what shall I do next?can you give me some detailed guides? Thank you very much!
    – Jason
    Jul 23, 2013 at 16:35
  • It's no problem to connect more than one signal handler. And if you need to trigger an emission of the draw signal, then use gtk_widget_queue_draw(). Unfortunately I can't give you a detailed guide without knowing what it is exactly that you are doing.
    – ptomato
    Jul 24, 2013 at 3:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.