On_draw function being called just by defining the function

I append a NoteBook->PAGE to the Page->GRID at (2,2) of the grid I add ScrolledWindow. Inside ScrolledWindow I added Viewport inside which I add DrawingArea.

On just defining the function on_draw I get a complete blank screen.
I am not even calling queue_draw.

And on_draw function has no statements inside it

Here’s the code on how I have placed the widgets using a function on a class

    // Creating new page tab label
	Gtk::Label *cameraName = new Gtk::Label(camString);
	// Create a new grid
	Gtk::Grid *newGrid = new Gtk::Grid();
	// Create a new scrolled window
	// Gtk::ScrolledWindow *newScrollWindow = new Gtk::ScrolledWindow();
	// Create a viewport
	Gtk::Viewport *newViewPort = new Gtk::Viewport(Gtk::Adjustment::create(0,0,0, 0.5),Gtk::Adjustment::create(0,0,0, 0.5));
	// Create a new DrawingArea
	Gtk::DrawingArea *newDrawingArea = new Gtk::DrawingArea();
    newGrid->attach(*Gtk::manage(new Gtk::ScrolledWindow()),2,2,1,1);


    // Here, you get a raw pointer to a widget:
    Gtk::Widget* pWidget = newGrid->get_child_at(2, 2);

    // We cast it to its most derived type:
    Gtk::ScrolledWindow* pScrolledWindow = dynamic_cast<Gtk::ScrolledWindow*>(pWidget);

    {    //Some property changes to the scrollWindow }

Inside the same class I have a member function called bool on_draw(const Cairo::RefPtr<Cairo::Context>& cr);

On just having a function without anything mentioned inside the function like this

bool CameraApplicationWindow::on_draw(const Cairo::RefPtr<Cairo::Context>& cr){
	    	std::cout<<"Inside on_draw"<<std::endl;

Code gets complied, on executing the output file.

I get a black screen on the GUI,

and on terminal only Inside on_draw gets printed again and again.

What am I doing wrong?

This is not really obvious, but I assume your class is a Gtk::Widget.

A Gtk::Widget (in Gtk3) has a “draw” signal, and the method for overriding default signal handlers in gtkmm is to provide an “on_<signalname>” method (Overriding default signal handlers) So you have basically overridden the draw functionality of your toplevel widget here.

Edit: sanitizer had eaten the signal name from the description

Could you please be more clear

Can you ask a more concrete question as which part I need to clarify?

When I remove the on_draw function. I can see the layout with scrolled and viewpoint.

If I keep the on_draw function as it is. I don’t see any widgets, on terminal I can see that on_draw function is being called repeatedly(just by defining it, I am not even calling it anywhere). I get a black screen as posted in the question.

I want to stop on_drawfunction being called with I run the complied file

Then rename it. on_draw is a special name in Gtk::Widget. Please check the site I linked: Overriding default signal handlers

I still need an on_draw which I can use to draw inside DrawingArea which is required according to this link

The on_draw would have to be in a child class of the Gtk::DrawingArea, or a differently named function that is bound to the “draw” signal of the drawing area externally with something like
drawingArea->signal_draw().connect( sigc::mem_fun(*this, &MyClass::entertain_drawing_area) );

Will try it out, thank you

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.