View Full Version : [Gtk] ProgressBar height

January 14th, 2013, 09:53 PM
How can I control the height of the BrogressBar, by default it's as high as other widgets, which is too high, ugly, see screenshot.

set_size_request and other approaches seem to fail, meanwhile the nautilus file I/O dialog box has a progress bar with a small height, which is what I need too.

set_margin_top/bottom is a hack around it that sort of works with unclear consequences.

#include <gtkmm.h>

int main(int argc, char *argv[]) {
Gtk::Main th(argc, argv);
Gtk::Window win;

mainBox.pack_start(box, false, true);

Gtk::ProgressBar p;
p.set_size_request(-1, 5);
box.pack_start(p, false, true);

Gtk::Button btn("OK");
btn.set_size_request(100, 100);
box.pack_start(btn, false, true);

win.set_size_request(600, 200);

January 15th, 2013, 12:32 PM
You are setting your button to a height of 100. Did you mean to do that? Image button perhaps?

Try adding another vertical box to contain the progress bar. Set the expand and fill to true when you add that box, but set the expand on the progress bar to false.

It's worth having a copy of Glade to play around with these things visually, even if you decide to build the UI in code.

January 15th, 2013, 02:55 PM
I'm setting the button so tall to show that the progress bar will also become as tall.
What you suggested doesn't seem to work, I wish the gtk progress bar height could be configured or was properly implemented.

January 15th, 2013, 03:06 PM
You need to use another Gtk::Box(let's name it x ) inside your Gtk::Box named box. You put your progress bar inside x and then x inside box.

I can't remember if x should have Gtk::ORIENTATION_HORIZONTAL or Gtk::ORIENTATION_VERTICAL. Try it out and see.

You should use Glade as a guide to how to do your GUI. Glade is a visual editor for Gtk.

January 15th, 2013, 03:48 PM
What you suggested doesn't seem to work ...
Maybe I didn't explain it fully enough. Here's a Python version that follows your code as closely as I can. (I'm not set up for gtkmm so this was quicker for me).

#!/usr/bin/env python

from gi.repository import Gtk

class Progress(Gtk.Window):

def __init__(self):
Gtk.Window.__init__(self, title='Progress')

main_box = Gtk.VBox(False, 0)
box = Gtk.HBox(False, 0)
main_box.pack_start(box, False, True, 0)

''' This is the new box for the progress bar '''
vbox = Gtk.VBox(False, 0)
box.pack_start(vbox, False, True, 0)

progress_bar = Gtk.ProgressBar()
vbox.pack_start(progress_bar, False, True, 0)

button = Gtk.Button('OK')
button.set_size_request(100, 100)
box.pack_start(button, False, True, 0)

self.set_size_request(600, 200)
self.connect("destroy", self.on_quit)

def on_quit(self, widget):

if __name__ == '__main__':

I'd probably set expand on the new box so that it fills the width, and the controls need padding but I wanted to follow your code.

January 15th, 2013, 04:19 PM
Thanks, your solution works, though it shows up the progress bar at the top, while I need it in the center (middle).

So while trying to center it vertically:

I noticed that now I don't need any helper boxes any longer, that line makes the progress bar both thin vertically and vertically aligned at the center (middle), so I shot 2 issues down with one bullet, boy is Gtk weird.

With this line of code adding the progress bar to the mainBox doesn't matter if filled/expanded are true or false - the progress bar stays always thin regardless, go figure.