Overlaying widgets


I would like to be able to overlay two widgets on top of each other - a GtkLabel on top of a GtkProgressBar - where the GtkLabel is centered on top of the GtkProgressBar.

I was looking the GtkOverlay widget, where the progress bar was the base/main widget and the label the overlaid widget. This works with one big exception that is a deal-breaker - I want to be able to show and hide the progress bar but have the label stay visible.

Originally, I thought that the GtkOverlay will do this simply because one of its children is still visible but that is not the case. As soon as I hide the progress bar, the label goes away, as well. Both the label and the GtkOverlay have their “visible” property still set to TRUE. It just seems that the GtkOverlay gets resized to 0.

Is there a better way to accomplish the layout that I am after? If not, is there a way to hide the GtkProgressBar but no release the space it occupies?

Thank you.

P.S. I know that I can set the CSS “opacity” property to 0 for the GtkProgressBar but I was hoping that there was a solution that did not require CSS.

Put the GtkProgressBar in a GtkStack with another GtkLabel that is empty. Switch to the label instead of hiding the progressbar.

Also set the GtkStack:homogeneous property to True.

Thank you for the suggestion. Unfortunately, that does not get me the solution that I really want.

Using a GtkStack means that only one of the widgets is visible at a time. What I want is the label to be always visible and the progress bar to appear and disappear when needed.

Read my reply again, I said “empty” label. Not the label you want floating above.

Ah, I see. It wasn’t clear that the GtkStack is the main widget is the GtkOverlay. Thank you.

Follow on question:

I’ve set the GtkOverlay that holds the stack and the label as the title widget for a GtkNotebook. All that seems fine but it turns out that I can’t switch pages anymore.

I am assuming that something in the widget tree is consuming the button-press event and it’s not making it to the GtkNotebook. What would be the best way to fix this? Event handlers on all the widgets in the tree that just propagate the events?

It seem that packing the GtkLabel that is the top overlay widget into an GtkEventBox works somewhat. Unfortunately, the GtkEventBox get a focus window when clicked even if the gtk_event_box_set_visible_window() is called.

Is there a way to avoid this?

Usually, gtk_widget_set_can_focus() to FALSE is enough to keep any widget from focusing.

The “can_focus” property is already set to FALSE. However, I noticed that even with a normal GtkNotebook, using a GtkLabel as the tab label, clicking on the label twice will focus the label. So, it turns out that what I am seeing is not out of the ordinary for a GtkNotebook.

Thank you for the help.

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