resander
June 29th, 2009, 04:05 PM
I am new to GTK and have difficulties in placing a vertical toolbar. I want it to occupy about 20% of the window on the left-hand side, but each toolbar item spans most of the window horizontally and is centered with a lot of blank space on either side.
I want the width of vertical toolbar to be the width of an icon plus a few pixels of margin around it.
Here is the problem as a minimal example:
window = gtk_window_new ( GTK_WINDOW_TOPLEVEL ) ;
gtk_window_set_title (GTK_WINDOW (window), "Vertical Toolbar" ) ;
gtk_widget_set_size_request (window, 450,300 ) ; // works
GtkWidget * box = gtk_hbox_new (TRUE, 0);
GtkWidget * toolbar = gtk_toolbar_new ();
gtk_widget_set_size_request (toolbar, 50,300 ) ; // doesn't work
gtk_toolbar_set_orientation( (GtkToolbar *)toolbar ,
GTK_ORIENTATION_VERTICAL ) ;
gtk_toolbar_set_icon_size ( (GtkToolbar *)toolbar , GTK_ICON_SIZE_SMALL_TOOLBAR ) ;
gtk_toolbar_set_style ( (GtkToolbar *)toolbar , GTK_TOOLBAR_ICONS ) ;
GtkToolItem * gtkimg = gtk_tool_button_new_from_stock ( GTK_STOCK_CUT ) ;
gtk_toolbar_insert( GTK_TOOLBAR(toolbar) , gtkimg , -1 ) ;
gtkimg = gtk_tool_button_new_from_stock ( GTK_STOCK_COPY ) ;
gtk_toolbar_insert( GTK_TOOLBAR(toolbar) , gtkimg , -1 ) ;
gtkimg = gtk_tool_button_new_from_stock ( GTK_STOCK_PASTE ) ;
gtk_toolbar_insert( GTK_TOOLBAR(toolbar) , gtkimg , -1 ) ;
gtk_box_pack_start_defaults (GTK_BOX (box), toolbar ) ;
gtk_container_add (GTK_CONTAINER (window), box);
gtk_widget_show_all (window);
gtk_main ();
It seems the size request gtk_widget_set_size_request (toolbar, 50,300 ) is ignored. My intent was to reserve 50 pixels for the the toolbar leaving 400 pixels for the neighbour(s) on the right-hand side, but it didn't work out like that.
How to modify the code above so the vertical toolbar comes out looking right?
I want the width of vertical toolbar to be the width of an icon plus a few pixels of margin around it.
Here is the problem as a minimal example:
window = gtk_window_new ( GTK_WINDOW_TOPLEVEL ) ;
gtk_window_set_title (GTK_WINDOW (window), "Vertical Toolbar" ) ;
gtk_widget_set_size_request (window, 450,300 ) ; // works
GtkWidget * box = gtk_hbox_new (TRUE, 0);
GtkWidget * toolbar = gtk_toolbar_new ();
gtk_widget_set_size_request (toolbar, 50,300 ) ; // doesn't work
gtk_toolbar_set_orientation( (GtkToolbar *)toolbar ,
GTK_ORIENTATION_VERTICAL ) ;
gtk_toolbar_set_icon_size ( (GtkToolbar *)toolbar , GTK_ICON_SIZE_SMALL_TOOLBAR ) ;
gtk_toolbar_set_style ( (GtkToolbar *)toolbar , GTK_TOOLBAR_ICONS ) ;
GtkToolItem * gtkimg = gtk_tool_button_new_from_stock ( GTK_STOCK_CUT ) ;
gtk_toolbar_insert( GTK_TOOLBAR(toolbar) , gtkimg , -1 ) ;
gtkimg = gtk_tool_button_new_from_stock ( GTK_STOCK_COPY ) ;
gtk_toolbar_insert( GTK_TOOLBAR(toolbar) , gtkimg , -1 ) ;
gtkimg = gtk_tool_button_new_from_stock ( GTK_STOCK_PASTE ) ;
gtk_toolbar_insert( GTK_TOOLBAR(toolbar) , gtkimg , -1 ) ;
gtk_box_pack_start_defaults (GTK_BOX (box), toolbar ) ;
gtk_container_add (GTK_CONTAINER (window), box);
gtk_widget_show_all (window);
gtk_main ();
It seems the size request gtk_widget_set_size_request (toolbar, 50,300 ) is ignored. My intent was to reserve 50 pixels for the the toolbar leaving 400 pixels for the neighbour(s) on the right-hand side, but it didn't work out like that.
How to modify the code above so the vertical toolbar comes out looking right?