gtkgtkmmgtkmm3gtkassistant

Using Gtk::Assistant in gtkmm3


I have a gtkmm3 application where I plan to use a class derived from Gtk::Assistant to perform some user configuration. As Gtk::Assistant is derived from Gtk::Window (and not Gtk::Dialog) there is no run() that I can call to get the assistant displayed.

As the good book says I use Gtk::Application::run(window) to bring up the main application window, but I'm clueless about how to show a second window from my main window in a gtkmm3 application. In gtkmm2.4 I'm pretty sure a Gtk::Main::run(assistant) would have done the job. I feel totally dumb that even after going through gtk-demo source code I am unable to figure this out. Some help would be appreciated.


Solution

  • You can simply call show(), like you would for any other window. For example:

    #include <gtkmm.h>
    
    class MainWindow : public Gtk::Window
    {
    
    public:
    
        MainWindow()
        {
            m_button.set_label("Click to show assistant...");
            m_button.signal_clicked().connect([this](){ShowAssistant();});
    
            add(m_button);
        }
    
    private:
    
        void ShowAssistant()
        {
            m_assistant.show();
        }
    
        Gtk::Button m_button;
        Gtk::Assistant m_assistant;
    };
    
    int main(int argc, char *argv[])
    {
        auto app = Gtk::Application::create(argc, argv, "gtkmm.example");
      
        MainWindow window;
        window.set_default_size(200, 200);
        window.show_all();
      
        return app->run(window);
    }