Progress Bar gtkmm3

Hello everyone,

I am studying the progress bar example from ;

https://developer-old.gnome.org/gtkmm-tutorial/3.24/sec-progressbar.html.en

but when I run it the height of the bar (fix distance that does not change) is very very thin and progress bar is updating as expected. Any ideas how to change this ? It doesn’t seem to be documented as far as I could check

Yeah, you need CSS for that:

#include <gtkmm.h>

#include <iostream>

void
on_css_parse_error(const Glib::RefPtr<const Gtk::CssSection>& section,
                   const Glib::Error& error)
{
  std::cerr << error.what() << "\n";
}

void
add_custom_style()
{
  static const char *css = ""
    "progressbar.thick trough {min-height: 30px;}\n"
    "progressbar.thick progress {min-height: 30px;}\n";
  Glib::RefPtr<Gtk::CssProvider> provider = Gtk::CssProvider::create();
  guint priority = GTK_STYLE_PROVIDER_PRIORITY_APPLICATION;

  provider->signal_parsing_error().connect(sigc::ptr_fun(on_css_parse_error));

  try {
    provider->load_from_data(css);
  }
  catch (const Gtk::CssProviderError &e) {
  }

  Gtk::StyleContext::add_provider_for_screen(Gdk::Screen::get_default(),
                                             provider,
                                             priority);
}

int main(int argc, char *argv[])
{
  auto app =
    Gtk::Application::create(argc, argv,
      "org.gtkmm.examples.base");

  add_custom_style();

  Gtk::Window window;
  window.set_default_size(440, 250);

  auto progress_bar = Gtk::make_managed<Gtk::ProgressBar>();
  progress_bar->set_hexpand();
  progress_bar->set_vexpand();
  progress_bar->set_halign(Gtk::ALIGN_CENTER);
  progress_bar->set_valign(Gtk::ALIGN_CENTER);
  progress_bar->set_fraction(0.5);

  progress_bar->get_style_context()->add_class("thick");

  window.add(*progress_bar);
  window.show_all();

  return app->run(window);
}
2 Likes

Thanks, that’s great ! :wink:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.