0

I have a function in gtkmm in the main window which opens a message box on the Help->About selection. The function is as follow:-

bool Main_window::on_about_selected(GdkEventButton *f_event)
 {
   Gtk::MessageDialog dialog(*this, "Msg Box example");
   // left the rest
   dialog.run();
 }

this pointer passes the Main_window since it calls the function.

How should i pass this argument when i want to call a message box dialog from another file other than the Main_window?

How do i set parent of this message dialog to be the window on which i want this to be called?

how do i get the top level window?

Majid Khan
  • 111
  • 2
  • 14

1 Answers1

0

That Gtk::Window is the transient-for (or parent) window, which associates the dialog window with a previously-open window.

If you want the dialog to have your main window as it's parent, you'll need to create some way to get that pointer to the main window. In an application, it's usually OK to just store it in a global variable. If it's not that simple for you, you'll need to invent your own system.

Calling Gtk::Widget::get_toplevel() on a child widget that you know about might help, but I suspect that it's not that simple. In particular, you'd have to be sure to only call it when you know that the child widget is really in a Gtk::Window.

murrayc
  • 2,103
  • 4
  • 17
  • 32