Re: Gtk::Menu No submenus.
- From: Paul Davis <pjdavis engineering uiowa edu>
- To: gtkmm list <gtkmm-list gnome org>
- Subject: Re: Gtk::Menu No submenus.
- Date: Sun, 14 May 2006 06:59:18 -0500
Mohammed,
Totally meant to write back the other day, but this one slipped my mind.
Not exactly sure what the problem is. You're working with references
and static objects. I'm not entirely sure how that affects things
really though. *All* of my widgets get allocated by doing
Gtk::Widget* blah = Gtk::manage( new Gtk::Widget() ) ;
When in Rome, try not to piss off the Romans. Dunno where I learned
this type of instantiation, but basically, for anything thats not a
window, do it this way. Oh, I think I got it by looking at the gtk--
generated C++ code IIRC.
Here is some working code:
#include <gtkmm.h>
class Win : public Gtk::Window {
public:
Win();
};
Win::Win()
{
Gtk::Menu* file_menu = Gtk::manage( new Gtk::Menu() ) ;
file_menu->items().push_back( Gtk::Menu_Helpers::StockMenuElem(
Gtk::StockID( "gtk-open" ) ) ) ;
Gtk::Menu* edit_menu = Gtk::manage( new Gtk::Menu() ) ;
edit_menu->items().push_back( Gtk::Menu_Helpers::StockMenuElem(
Gtk::StockID( "gtk-copy" ) ) ) ;
Gtk::MenuBar* main = Gtk::manage( new Gtk::MenuBar() ) ;
main->items().push_back( Gtk::Menu_Helpers::MenuElem( "_File",
*file_menu ) ) ;
main->items().push_back( Gtk::Menu_Helpers::MenuElem( "_Edit",
*edit_menu ) ) ;
add( *main ) ;
show_all_children();
}
int main(int argc, char *argv[])
{
Gtk::Main kit(&argc, &argv);
Win win;
kit.run(win);
return 0;
}
Hope that helps
Cheers,
Paul
Mohammed Sameer wrote:
On Thu, May 11, 2006 at 08:58:33AM -0500, Jonathon Jongsma wrote:
On 5/11/06, Mohammed Sameer <msameer foolab org> wrote:
Hi all,
I'm still a gtkmm newbie.
I'm subclassing Gtk::Window and creating a menubar in the
constructor "see the attached code please".
The menubar is created but it has no sub menus,
Did I hit a bug ? Or am I doing something wrong ?
Attached a code sample:
g++ -o m m.cc `pkg-config gtkmm-2.4 --cflags --libs`
I haven't looked at your example code closely yet, but I would highly
recommend that you look into using UIManager instead of building the
menus manually. UIManager offers a lot of advantages, including
easily defining a menu structure as an XML tree. In addition, it
allows you to define menu items in terms of "Actions". You can then
assign the same action to a toolbar button so that the Open item in
your menu and the Open button on your toolbar will do exactly the same
thing. Because of this, you can then enable / disable these two
things together, and other things. I've found it to be very easy to
use. See this section in the tutorial for information:
http://www.gtkmm.org/docs/gtkmm-2.4/docs/tutorial/html/ch11.html
I know about the UIManager but I'm porting from C/Gtk to C++/Gtkmm.
I really don't want to change the way I build the UI as I want it to
run on older gtkmm versions as well.
There's also the "hacker" attitude, You can't hit a problem and simply switch
to another approach before understanding what's going on ;-)
Many thanks for your reply.
------------------------------------------------------------------------
_______________________________________________
gtkmm-list mailing list
gtkmm-list gnome org
http://mail.gnome.org/mailman/listinfo/gtkmm-list
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]