Jason
Jason

Reputation: 43

Can I draw a rectangle in GtkWindow directly without GtkDrawingArea?

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!

Upvotes: 4

Views: 911

Answers (1)

ptomato
ptomato

Reputation: 57854

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.

Upvotes: 2

Related Questions