Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you layer two widgets on top of each other while retaining layout capabilities?

While developing Qt UIs, I often want to display a notification or other display tool on top of an existing UI.

However, I have only discovered two ways of doing this, but neither completely solves the problem.

Option 1

Make the notification widget a sibling of the displayed widgets, but don't add it to any layout and raise it above the other one.

Problem: The widget can't be in a layout, and so you have to manually size it to fit it's contents, and you have to move it to the correct position whenever the parent window is resized.

Option 2

Add the widget to the layout right alongside the displayed widgets.

Problem: Since the widget is part of the layout, it moves the other displayed widgets around when it is visible, rather than on top of them.

Example - here the notification pushes the "v0.3b" label upwards rather than appearing on top of it. On the upside, since it is part of the layout with the spacer on its left, it is sized appropriately to its contents. enter image description here

Solution

Is there something like a QStackedWidget that displays multiple pages at once, with the empty area showing the widgets beneath? Is there another option for this kind of UI feature?

like image 239
Cory Klein Avatar asked Jul 19 '13 22:07

Cory Klein


1 Answers

You are right, QStackedWidget/QStackedLayout is your friend. Make a custom widget with stacked layout, when message comes in, you set active widget to the one with warning message, with a timer, you flip back to normal one. This custom widget can be placed in the main window in bottom right corner. With spacer, this can be done fairly easy, right?

like image 130
user3195397 Avatar answered Sep 21 '22 08:09

user3195397