'GTK drawing area is not realized
In my application I am using a Gtk::DrawingArea like this:
Window win;
DrawingArea area;
Box box(ORIENTATION_VERTICAL);
area.signal_realize().connect(sigc::ptr_fun(&on_video_area_realize));
box.pack_start(myWidgets, true, true);
box.pack_start(area, false, false);
win.add(box);
win.show_all();
The problem is, the function on_video_area_realize is not being called and if I query the status of the DrawingArea with area.get_realized(), it is false, so it has not been realized yet.
I do not understand why it has not been realized? As far as I understand, a widget is realized when it is added to a window - which, as far as I think, I am doing already.
Solution 1:[1]
The realize signal happens when the window (and its children) is showed. The following code (I tested this with Gtkmm 3.24.20):
#include <iostream>
#include <gtkmm.h>
void on_video_area_realize()
{
std::cout << "Video drawing area realized!" << std::endl;
}
int main(int argc, char *argv[])
{
std::cout << "Gtkmm version : " << gtk_get_major_version() << "."
<< gtk_get_minor_version() << "."
<< gtk_get_micro_version() << std::endl;
auto app = Gtk::Application::create(argc, argv, "org.gtkmm.examples.base");
Gtk::Window window;
Gtk::Box layout{Gtk::ORIENTATION_VERTICAL};
Gtk::Label label{"Example"};
std::cout << "Checkpoint 1" << std::endl;
Gtk::DrawingArea area;
std::cout << "Checkpoint 2" << std::endl;
area.signal_realize().connect(sigc::ptr_fun(&on_video_area_realize));
std::cout << "Checkpoint 3" << std::endl;
layout.pack_start(label, true, true);
layout.pack_start(area, false, false);
std::cout << "Checkpoint 4" << std::endl;
window.add(layout);
window.show_all();
std::cout << "Checkpoint 5" << std::endl;
return app->run(window);
}
Yields the following output:
Gtkmm version : 3.24.20
Checkpoint 1
Checkpoint 2
Checkpoint 3
Checkpoint 4
Video drawing area realized!
Checkpoint 5
From this, we can see that the drawing area is realized, but not when added to the window.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | BobMorane |
