Re: nonmodal dialog, additional main windows



On Sun, 12 Apr 2009 16:08:32 -0500
"Fleming, Matthew" <mfleming mcw edu> wrote:
> Folks,
> 
> Would really appreciate your help with the following. If its not
> obvious, I'm a neophyte with gtkmm.
> 
> I would like to create a nonmodal (nonblocking) dialog. I can create
> a dialog by subclassing Gtk::Dialog and using the run method of the
> subclass to show it. This works fine but the dialog is modal. I have
> tried making it nonmodal by calling show() instead of run() but then
> it doesn't appear at all. I have also tried making it nonmodal by
> calling the constructor of the superclass (ie Dialog) with the modal
> argument set to false, in the initialization list of my subclass'
> constructor, but this doesn't seem to change anything.
> 
> I thought perhaps I should subclass Gtk::Window instead of
> Gtk::Dialog to get around the problem. But I don't seem to be able to
> show a second main window. I show the first with Gtk::Main.run() and
> tried to show a second with its show() method, but it doesn't appear.
> 
> I apologize if these questions have simple answers. I'm mostly a java
> programmer and this stuff works quite differently in java, which may
> explain my confusion. Thanks in advance for your help.

If you do not want a modal dialog then don't call Gtk::Dialog::run().
That method recursively calls gtk_main()/Gtk::Main::run() and so blocks.

Probably you need to call show_all() rather than show().  You will also
need to create the object on the heap with the new expression (if you
create it as a local object then you won't see it because it will go
out of scope, and so be destroyed, immediately after it is constructed).

You will therefore also need to free it when you have finished with it.
Since it will have a virtual destructor, 'delete this' will do the trick
provided that it is the last thing that you call on the object
concerned.  Some people do this in a handler for the hide signal.

Chris


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]