GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Thu Oct 23, 2014 12:40 am

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Fixed size buttons
PostPosted: Wed Apr 30, 2008 3:16 pm 
Offline

Joined: Wed Apr 30, 2008 2:58 pm
Posts: 2
Hello,

I am placing a button inside of a frame. I want the frame to expand/contract as I resize the window, but I want the button to remain of the same size. Right now the button grows alongwith the frame and it looks ugly. Could someone help me out?

Heres a sample code. In this code an entry box and a button are placed side-by-side. I want the entrybox to grow as the window is expanded but the button should remain the same size.

[code=]
#include <gtk/gtk.h>

int main( int argc,
char *argv[] )
{
/* GtkWidget is the storage type for widgets */
GtkWidget *window;
GtkWidget *frame, *ok_button;
GtkWidget *vbox, *hbox;
GtkWidget *entry;

/* Initialise GTK */
gtk_init (&argc, &argv);

window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), "Frame Example");

g_signal_connect (G_OBJECT (window), "destroy",
G_CALLBACK (gtk_main_quit), NULL);
gtk_widget_set_size_request (window, 300, 300);
gtk_container_set_border_width (GTK_CONTAINER (window), 10);

/* Create a Frame */
frame = gtk_frame_new (NULL);
gtk_container_add (GTK_CONTAINER (window), frame);
gtk_frame_set_label (GTK_FRAME (frame), "GTK Frame Widget");

vbox = gtk_vbox_new(FALSE, 5);
gtk_container_add(GTK_CONTAINER(frame), vbox);

hbox = gtk_hbox_new(FALSE, 5);
gtk_container_add(GTK_BOX(vbox), hbox);

entry = gtk_entry_new ();
gtk_container_add(GTK_BOX(hbox), entry);

ok_button=gtk_button_new_from_stock(GTK_STOCK_SAVE);
gtk_box_pack_start(GTK_BOX(hbox), ok_button, TRUE, TRUE, 0);

/* Display the window */
gtk_widget_show_all(window);

/* Enter the event loop */
gtk_main ();

return 0;
}[/code]

Sachin.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 30, 2008 3:21 pm 
Offline

Joined: Wed Apr 30, 2008 2:58 pm
Posts: 2
Haha, just after posting I got the solution. The trick was to set the expand parameter in gtk_box_pack_start to FALSE. Hope it helps someone else.

Sachin.
My Pidgin Plugin


Top
 Profile  
 
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: Google [Bot] and 2 guests


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