0

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.

BobMorane
  • 3,870
  • 3
  • 20
  • 42
Mohith
  • 75
  • 7

1 Answers1

0

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);
}
BobMorane
  • 3,870
  • 3
  • 20
  • 42
  • 1
    Thank you for the detailed answer... I realised my mistake, I was creating the `Gtk::Assistant` instance inside a member function of the main window. So as soon as execution leaves the function the instance would get deleted and the call to `show()`, being a non-blocking function, would have no effect. Thank you once again. – Mohith Jul 10 '21 at 03:50