Search code examples
gtkgtkmm

Gtk Spinner Not Appearing


I'm trying to get a Gtk::Spinner object to display while calculations are in progress but nothing appears to be happening. The snippet of code looks like...

{
    Gtk::Spinner spinner;
    spinner.start (); 
    // do some work...
    spinner.stop ();
}

I'd have thought the spinner needed to know which dialogue it appears over but I can't see any way of feeding that into the object. Does anyone know where I could find a worked example? I can find the Gtk documentation in many places, but that isn't helping much.


Solution

  • To change the mouse cursor to "busy" you can do the following:

    Glib::RefPtr<Gdk::Window> window = dialog.get_window();
    if(window) {
        window->set_cursor(Gdk::Cursor(Gdk::WATCH));
        Gdk::flush();
    }
    

    To change it back, do

    window->set_cursor();
    

    instead.

    Disclaimer: I usually work with GTK in C, and have translated this on the fly...