Sign in to follow this  
mynameisnafe

GTK / C++ Window - VBOX with widgets not showing

Recommended Posts

mynameisnafe    258

Hi Guys,

 

I'm playing with GTK on Ubuntu, trying to make a simple text editor. I've got a window, it's very pretty.

 

Unfortunately, I've been trying to add some widgets to this window and I can't seem to make them show up.

 

I've no idea why they're not showing up.. perhaps someone could shed some light on this for me?

The following code should illicit a window complete with menu bar, textview in a scrolled container, and a status bar - it illicits an empty window:

 

#include <gtk/gtk.h>

int main ( int argc, char *argv[] )
{
	/* I want a Window with a vertical box layout */

	GtkWidget *window;
	GtkWidget *verticalLayout;

	/* Also, I want a scrollable textview */

	GtkWidget *textview;
	GtkWidget *scrollable;

	/* And a status bar, and a menu bar */
	GtkWidget *menu_bar;
	GtkWidget *status_bar;
	GtkWidget *file, *edit, *tools;

	/* 
		Initialise GTK et al
	*/

	gtk_init (&argc, &argv);

	/* Give window*/
	window = gtk_window_new( GTK_WINDOW_TOPLEVEL );
		
	gtk_window_set_title( GTK_WINDOW( window ), "Editor" );
	gtk_window_set_position( GTK_WINDOW( window ), GTK_WIN_POS_CENTER);
	gtk_window_set_default_size ( GTK_WINDOW( window ), 600, 400);
	
	verticalLayout = gtk_box_new( GTK_ORIENTATION_VERTICAL, 2 );
	
	gtk_container_add(GTK_CONTAINER( window ), verticalLayout);
	
	/* Give Menu Bar */
	menu_bar = gtk_menu_bar_new();
	
	file = gtk_menu_item_new_with_label("File");
	
	gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar), file );
	
	gtk_box_pack_start(GTK_BOX(verticalLayout), menu_bar, FALSE, FALSE, 3 );
	
	/* Give textview */

	textview = gtk_text_view_new();
	
	scrollable = gtk_scrolled_window_new(NULL, NULL);
	
	gtk_container_add( GTK_CONTAINER( scrollable ), textview ); // text view in scrollable
	
	gtk_box_pack_start( GTK_BOX( verticalLayout ), scrollable, TRUE, TRUE, 5 ); //scrollable in vbox

	/* Give Status Bar */
	
	status_bar = gtk_statusbar_new();
	
	gtk_box_pack_end( GTK_BOX(verticalLayout), status_bar, TRUE, TRUE, 3 );


	/* Connect the destroy signal to the x button callback */
	g_signal_connect( window, "destroy", G_CALLBACK (gtk_main_quit), NULL );

	/*	To Do - add other callbacks */

	/*
		Show the window
	*/
	gtk_widget_show (window);

	/*
		Enter the main() of the window and process callbacks as 
		they happen
	*/
	
	gtk_main ();

	return 0;
}

Thanks in advance,

 

N

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this