GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Fri Oct 31, 2014 9:08 am

All times are UTC




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Is there an easy way of putting a Quit button botton center
PostPosted: Thu Jan 05, 2012 7:10 am 
Offline
GTK+ Geek

Joined: Sun Dec 04, 2011 9:29 pm
Posts: 71
Location: Seattle, WA
This should be easy but I'm having trouble finding a straightforward answer. I'm tired of having to kill my gtk application and looking for an easy way of putting a Quit button at the center bottom? Is there an easy way ?

Thanks.


Top
 Profile  
 
 Post subject: Re: Is there an easy way of putting a Quit button botton ce
PostPosted: Thu Jan 05, 2012 8:24 am 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 768
Location: UK
Hi,

Without knowing your current layout of your application I am going to make some assumptions and hopefully you can apply the information to your code. Also I do not know which version of GTK you are using, so I will try to make the information fairly general to apply to versions 2 and 3.

I will assume that you first have a GtkBox with vertical orientation (GTK 3) or GtkVBox (GTK 2) containing the contents of your application. You will need an empty space at the end to place your next object.

http://developer.gnome.org/gtk3/stable/GtkBox.html
http://developer.gnome.org/gtk3/stable/GtkVBox.html

Your next object is GtkButtonBox with horizontal orientation (GTK 3) or GtkHButtonBox (GTK 2), this is to be placed in the last position of the GtkBox/GtkVBox. This controls the layout of the buttons that would be added so what you need is
Code:
    gtk_buttonbox_set_layout(GTK_BUTTONBOX(widget), GTK_BUTTONBOX_CENTER);
to set the button to be centred.

http://developer.gnome.org/gtk3/stable/GtkButtonBox.html
http://developer.gnome.org/gtk3/stable/GtkHButtonBox.html

Next you will need to add your button or buttons. Since GtkButtonBox/GtkHButtonBox is derived from GtkContainer you will use the function "gtk_container_add ()" to add you button or buttons.

http://developer.gnome.org/gtk3/stable/GtkContainer.html

Basically what I have described here is the bases of GtkDialog, which if the situation is right could be used instead.

http://developer.gnome.org/gtk3/stable/GtkDialog.html

You could also consider having a menu bar at the top of your applications main window. The menu bar does not need to be big ie. not too many menu items, but you could have a "Quit" menu item which also has a keyboard binding which is normally "CTRL+Q".

_________________
E.


Top
 Profile  
 
 Post subject: Re: Is there an easy way of putting a Quit button botton ce
PostPosted: Thu Jan 05, 2012 7:25 pm 
Offline
GTK+ Geek

Joined: Sun Dec 04, 2011 9:29 pm
Posts: 71
Location: Seattle, WA
I have learned that i have gtk2 and/or gtk2+, not gtk3, so i will look for a corresponding site! thanks much.


Top
 Profile  
 
 Post subject: Re: Is there an easy way of putting a Quit button botton ce
PostPosted: Thu Jan 05, 2012 7:47 pm 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 768
Location: UK
The Documentation for GTK 2 can be found at http://developer.gnome.org/gtk/stable/

In this case there are not too many differences between GTK 2 and GTK 3 only GtkVBox and GtkHButtonBox have been deprecated in GTK 3, but are still available. The widgets you need to look for are GtkVBox, GtkHButtonBox, GtkContainer and possibly GtkDialog if you want a simple way of doing this.

_________________
E.


Top
 Profile  
 
 Post subject: Re: Is there an easy way of putting a Quit button botton ce
PostPosted: Thu Jan 05, 2012 8:30 pm 
Offline
GTK+ Geek

Joined: Sun Dec 04, 2011 9:29 pm
Posts: 71
Location: Seattle, WA
thanks for your reply. it looks like i'm in the midst of being caught in the change-over from 2 to 3. --oh well.
i guess that's the price to pay for jumping in to gtk and GUI since 2002!


Top
 Profile  
 
 Post subject: Re: Is there an easy way of putting a Quit button botton ce
PostPosted: Thu Jan 05, 2012 9:48 pm 
Offline
GTK+ Geek

Joined: Sun Dec 04, 2011 9:29 pm
Posts: 71
Location: Seattle, WA
errol wrote:
The Documentation for GTK 2 can be found at http://developer.gnome.org/gtk/stable/

In this case there are not too many differences between GTK 2 and GTK 3 only GtkVBox and GtkHButtonBox have been deprecated in GTK 3, but are still available. The widgets you need to look for are GtkVBox, GtkHButtonBox, GtkContainer and possibly GtkDialog if you want a simple way of doing this.

Here is a file, quir.c, that I modified from one I had in my gtk directory. Is there a way of centering the 'Quit' button?
I think it is enclosed; it has been years since I used phpBB...

Anyway, the last several lines of my speech application are:
Code:
run = gtk_button_new_from_stock ("Run Text-To-Speech");
   g_signal_connect (run, "clicked", G_CALLBACK (run_button_click_cb), NULL);

   gtk_box_pack_start (GTK_BOX (vbox), run, 0, 0, 0);

   gtk_widget_show_all (window);
   gtk_main ();
   return 0;
}

So I'm not even sure my kwik hack quit code will even display. hm. I don't see quit.c but I did send it....

Thanks either way.


Top
 Profile  
 
 Post subject: Re: Is there an easy way of putting a Quit button botton ce
PostPosted: Sat Jan 07, 2012 9:23 am 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 768
Location: UK
This will place the button at the end of the GtkVBox, but it will be the width of the GtkVBox. If that is fine all is OK

If you need the button to be button sized then I would suggest containing your button in a GtkHButtonBox setting the options to place the buttons centre, then add that to your GtkVBox. This way if you need extra buttons to match the layout it is a simple case of adding them to the GtkHButtonBox.

_________________
E.


Top
 Profile  
 
 Post subject: Re: Is there an easy way of putting a Quit button botton ce
PostPosted: Sat Jan 07, 2012 10:09 pm 
Offline
GTK+ Geek

Joined: Sun Dec 04, 2011 9:29 pm
Posts: 71
Location: Seattle, WA
Well, I figured it out myself the best way I knew how: I just stuck a vertical quit button in to main() function:

Code:
entry = gtk_entry_new_with_max_length (50);
   gtk_signal_connect (GTK_OBJECT (entry), "activate",
                       GTK_SIGNAL_FUNC (enter_callback), entry);

   hbox = gtk_hbox_new (FALSE, 0);
   gtk_container_add (GTK_CONTAINER (vbox), hbox);
   gtk_widget_show (hbox);

   button = gtk_button_new_with_label ("Quit");
   gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
                              GTK_SIGNAL_FUNC (gtk_exit),
                              GTK_OBJECT (window));
   gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0);
   GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
   gtk_widget_grab_default (button);

The "enter_callback()" fn seems to have some surplus code ... gotta check that.
This works for now, but I would very much appreciate it if anybody could clean up any unnecessary code. I'm learning by actually writing .... even if it means stumbling.

tia people.


Top
 Profile  
 
 Post subject: Re: Is there an easy way of putting a Quit button botton ce
PostPosted: Sun Jan 08, 2012 9:33 am 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 768
Location: UK
That looks OK apart from you are using a function that was deprecated with the change from GTK 1.2 to 2.0.

Please use g_signal_connect_swapped() instead of gtk_signal_connect_object() and g_signal_connect() instead of gtk_signal_connect().

_________________
E.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 1 guest


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