Seeing blank window if child is gtk stack switcher

Here is a small piece of code

#include <gtk/gtk.h>

static void activate( GtkApplication *app, gpointer user_data )
{
	GtkWidget *window = gtk_application_window_new( app );
	GtkWidget *stk_switcher = gtk_stack_switcher_new();
	gtk_window_set_child( (GtkWindow*)window, stk_switcher );
	GtkWidget *stack = gtk_stack_new();
	gtk_stack_switcher_set_stack( (GtkStackSwitcher*)stk_switcher, (GtkStack*)stack );
	gtk_stack_add_named( (GtkStack*)stack, gtk_check_button_new_with_label( "Check Button 1" ), "Stack Page 1" );
	gtk_stack_add_named( (GtkStack*)stack, gtk_check_button_new_with_label( "Check Button 2" ), "Stack Page 2" );
	gtk_widget_show( window );
}

int main( int argc, char **argv )
{
	GtkApplication *app = gtk_application_new( "this.is.my.stk.appln", G_APPLICATION_FLAGS_NONE );
	g_signal_connect( app, "activate", G_CALLBACK( activate ), NULL );
	int status = g_application_run( G_APPLICATION( app ), argc, argv );
	g_object_unref( app );

	return status;
}

I am just seeing a blank window. Not able to understand whats wrong.

And what GTK version are you using?

You aren’t adding the Stack to the window at all. gtk_stack_switcher_set_stack() doesn’t do that, it just determined which stack the switcher controls.

Thanks. issue solved with the following code…!!!

static void activate( GtkApplication *app, gpointer user_data )
{
	GtkWidget *window = gtk_application_window_new( app );
	GtkWidget *stk_switcher = gtk_stack_switcher_new();
	GtkWidget *stack = gtk_stack_new();
	GtkWidget *box = gtk_box_new( GTK_ORIENTATION_HORIZONTAL, 5 );
	gtk_window_set_child( (GtkWindow*)window, box );
	gtk_stack_switcher_set_stack( (GtkStackSwitcher*)stk_switcher, (GtkStack*)stack );
	gtk_stack_add_titled( (GtkStack*)stack, gtk_check_button_new_with_label( "Check Button 1" ), "StackPage1", "page1" );
	gtk_stack_add_titled( (GtkStack*)stack, gtk_check_button_new_with_label( "Check Button 2" ), "StackPage2", "page2" );
	GtkWidget *side_bar = gtk_stack_sidebar_new();
	gtk_stack_sidebar_set_stack( (GtkStackSidebar*)side_bar, (GtkStack*)stack );
	gtk_box_append( (GtkBox*)box, side_bar );
	gtk_box_append( (GtkBox*)box, stack );
	gtk_widget_show( window );
}

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