My Gtk.DrawingArea appears only if I add it as a widget to the main window. If there is a fixed container in the Window and I add the DrawingArea to the fixed container, I see nothing. But I know the draw signal is been called when debugging.
Gtk.DrawingArea drawing_area = new Gtk.DrawingArea ();
drawing_area.draw.connect ((context) => {
context.set_source_rgba (1, 0, 0, 1);
context.rectangle (25, 25, 100, 100);
context.fill ();
return true;
});
// Doesn't work, nothing is visible
fixed.put (drawing_area, 25, 25);
The variable fixed is of type Gtk.Fixed. fixed is the only child widget of the main window. I must mention that if I add any other normal Gtk Widget to fixed, like a label, said label is visible.
If I, instead of adding fixed to my main window, I add the drawing area as the only child of the main window like in the following code, it displays
// Works, rectangle is visible
app_window.add (drawing_area);
app_window is of type Gtk.ApplicationWindow.
Is it possible to make it visible while being a child of Fixed?
----------Edit----------
The Gtk.DrawingArea now appears in the fixed container if I set the size requests for it. Like this
Gtk.DrawingArea drawing_area = new Gtk.DrawingArea ();
drawing_area.width_request = 100;
drawing_area.height_request = 100;
drawing_area.draw.connect ((context) => {
context.set_source_rgba (1, 0, 0, 1);
context.rectangle (0, 0, drawing_area.get_allocated_width (), drawing_area.get_allocated_height ());
context.fill ();
return true;
});
I don't know if this is the correct way to go about it. It works though. The DrawingArea widget with the rectangle displays now in the fixed container. I'll listen to other answers if there is a recommended way to go about it.
One has to set the size requests of the Gtk.DrawingArea widget.
Gtk.DrawingArea drawing_area = new Gtk.DrawingArea ();
drawing_area.width_request = 100;
drawing_area.height_request = 100;
drawing_area.draw.connect ((context) => {
context.set_source_rgba (1, 0, 0, 1);
context.rectangle (0, 0, drawing_area.get_allocated_width (), drawing_area.get_allocated_height ());
context.fill ();
return true;
});