GTK+ Forums Forum Index GTK+ Forums
Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Fixed size buttons

 
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming
Author Message
sachins



Joined: 30 Apr 2008
Posts: 2

PostPosted: Wed Apr 30, 2008 3:16 pm    Post subject: Fixed size buttons Reply with quote

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: (Plaintext)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48

#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;
}


Sachin.
Back to top
sachins



Joined: 30 Apr 2008
Posts: 2

PostPosted: Wed Apr 30, 2008 3:21 pm    Post subject: Reply with quote

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
Back to top
Display posts from previous:   
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming All times are GMT
Page 1 of 1

 


Powered by phpBB © 2001, 2005 phpBB Group
CodeBB 1.0 Beta 2
Protected by Anti-Spam ACP