Jump to content

  • Log In with Google      Sign In   
  • Create Account


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


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 mynameisnafe   Members   -  Reputation: 252

Like
0Likes
Like

Posted 06 May 2013 - 12:47 PM

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



Sponsor:

#2 mynameisnafe   Members   -  Reputation: 252

Like
0Likes
Like

Posted 19 May 2013 - 06:11 AM

What, nobody?






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS