Deprecation of GtkDialog

Hello,

I understand that GtkDialog has been deprecated.

It had a function

GtkWidget* gtk_dialog_get_content_area(GtkDialog* dialog)

that I used to retrieve the GtkBox to add child widgets to.

When I replace the GtkDialog with a GtkWindow as:

  <object class="GtkWindow" id="gtk_window_1"><style><class name="gtk_window_1"></class></style>
    <child>
      <object class="GtkGrid" id="gtk_grid_18">
      </object>
    </child>
  </object>

and

void		gtk_window_1_on_realize		(GtkWidget* gtk_window_1, gpointer user_data)
{
		gtk_grid_18 = gtk_builder_get_object(gtk_builder_0, "gtk_grid_18");
}

I have a GtkGrid similar to the GtkBox. It can be used to add child widgets.

When I replace the GtkDialog with a GtkWindow as:

  <object class="GtkWindow" id="gtk_window_1"><style><class name="gtk_window_1"></class></style>
  </object>
void		gtk_window_1_on_realize		(GtkWidget* gtk_window_1, gpointer user_data)
{
		gtk_grid_18 = gtk_grid_new();
                      gtk_widget_set_parent(GTK_WIDGET(gtk_grid_18), gtk_window_1);
}

I get the following error:

Trying to snapshot GtkGrid 0x… without a current allocation

When looking at the variables that I consider relevant in connection to this allocation, I get for both methods exactly the same width, height and baseline.

gtk_window_1 : 0000000000E93E60
gtk_window_1 parent : 0000000000000000
gtk_window_1 layout : 0000000000000000
gtk_window_1 width : 0
gtk_window_1 height : 0
gtk_window_1 baseline: -1
gtk_grid_18 : 0000000001B36FC0
gtk_grid_18 parent : 0000000000E93E60
gtk_grid_18 layout : 0000000001B370A0
gtk_grid_18 width : 0
gtk_grid_18 height : 0
gtk_grid_18 baseline: -1

Can someone please tell me what I’m doing wrong?

Best regards,
Mischa Baars, The Netherlands.

Hi,

When is gtk_window_1_on_realize called? is it a callback on the realize signal?

If yes that doesn’t sound sane, Gtk is trying to display the window but at the same time you add stuff in there, so of course it can’t compute its allocation properly.

Why not adding the GtkGrid at the GtkWindow’s initialization?

Hi G,

Thank you for your timely response. Lucky for you, I already found the answer:

The first widget added to a window requires not calling

void gtk_widget_set_parent(GtkWidget* widget, GtkWidget* parent)

but calling

void gtk_window_set_child(GtkWindow* window, GtkWidget* child)

This resolves the allocation issue.

Best regards,
Mischa Baars.

1 Like

Yes, set_parent() is for widget/container implementations, not general use.

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