GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Sun Aug 28, 2016 2:03 pm

All times are UTC

Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: how to check which child is in the container
PostPosted: Sat Jun 30, 2012 1:20 pm 

Joined: Thu Jun 28, 2012 3:27 pm
Posts: 1
Hey everyone,

the action of my toolbar buttons are dependent on the child widget in one of the containers (the button changes the child, for that I need to know which child to remove and which to add; at least this is the way I thought of).

How can I check which child is parented by the container? I know that there is a get_child method, but how can I compare the return value?

Thanks in advance

 Post subject: Re: how to check which child is in the container
PostPosted: Sun Jul 01, 2012 1:01 am 
GTK+ Guru

Joined: Fri Mar 25, 2011 5:16 pm
Posts: 181
Location: USA
I don't understand what you mean: "dependent on the child widget in one of the containerS"
Normally a toolbar is in just one container like a vbox and each addition to the toolbar has an index which can be used to refer to that button. Could you post what code you have? Here's a modified example from
/* COMPILE WITH:  gcc -Wall -o tool1 `pkg-config --cflags --libs gtk+-3.0` tool1.c  */

#include <gtk/gtk.h>

int main( int argc, char *argv[])
  GtkWidget *window;
  GtkWidget *vbox, *toolbar;
  GtkToolItem *new, *open, *save, *sep, *exit;

  gtk_init(&argc, &argv);

  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
  gtk_window_set_default_size(GTK_WINDOW(window), 250, 200);
  gtk_window_set_title(GTK_WINDOW(window), "toolbar");

  vbox = gtk_vbox_new(FALSE, 0);
  gtk_container_add(GTK_CONTAINER(window), vbox);

  toolbar = gtk_toolbar_new();
  gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_ICONS);

  gtk_container_set_border_width(GTK_CONTAINER(toolbar), 2);

  new = gtk_tool_button_new_from_stock(GTK_STOCK_NEW);
  gtk_toolbar_insert(GTK_TOOLBAR(toolbar), new, 0);

  open = gtk_tool_button_new_from_stock(GTK_STOCK_OPEN);
  gtk_toolbar_insert(GTK_TOOLBAR(toolbar), open, 1);

  save = gtk_tool_button_new_from_stock(GTK_STOCK_SAVE);
  gtk_toolbar_insert(GTK_TOOLBAR(toolbar), save, 2);

  sep = gtk_separator_tool_item_new();
  gtk_toolbar_insert(GTK_TOOLBAR(toolbar), sep, 3);

  exit = gtk_tool_button_new_from_stock(GTK_STOCK_QUIT);
  gtk_toolbar_insert(GTK_TOOLBAR(toolbar), exit, 4);

  gtk_box_pack_start(GTK_BOX(vbox), toolbar, FALSE, FALSE, 5);

  g_signal_connect(G_OBJECT(exit), "clicked",
        G_CALLBACK(gtk_main_quit), NULL);

  g_signal_connect_swapped(G_OBJECT(window), "destroy",
        G_CALLBACK(gtk_main_quit), NULL);

  return 0;

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC

Who is online

Users browsing this forum: No registered users and 1 guest

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group