Overlaying responsive Widgets
-
Hello everyone,
I am completely new to Qt and am trying to design a UI for an experimental application I am working on. I am trying to do the following:
I have a QGraphicsView showing a scene and I want to have a smaller fixed sized QGraphicsView on top in the corner serving as a "minimap" overlay for the current view of the main graphics view. Additionally, I want the main QGraphicsView to be responsive to resizing and the smaller "minimap" graphics view to stay in the top right corner as well.
Currently, my best solution was to create the main QGraphicsView and create a sibling QWidget containing the smaller QGraphicsView. The "minimap" is be situated inside this widget using a grid layout and horizontal/vertical spacers to keep it in the corner. As far as I understand, as long as the other widget is on top of the main QGraphicsView, both should be visible, which is what I want as the minimap should just overlay in the corner, but otherwise the main QGraphicsView should be fully visible.
The problem is now that I cannot use a VBoxLayout on the central widget (which the main QGraphicsView and its sibling QWidget containing the "minimap" are children of) to achieve responsive resizing, since the widgets are than placed according to the layout. Is there a manual way to create the responsive behavior without the use of layouts and would this approach even achieve what I am trying to do? I am unable to find any other topics on this forum (there may be, but I might just search using the wrong keywords).Any help is greatly appreciated. Thanks in advance!
-
@srcdc
I have never done this, and I may be wrong/stand to be corrected. I have always used layouts but my understanding is that if you want widgets to overlay one another set so the child has the parent as itsparent
but do not put it on a layout. Rather, use absolute positioning on it, which is treated as relative to its parent. Easy enough for top-left (i.e.(0, 0)
), you may have to do something to achieve top-right where the parent widget can be resized. -
@JonB
Nice, I guess that solves my problem. The main QGraphicsView is added to the layout and thus remains responsive when resizing. For the minimap I just set the parent, but don't add it to the layout so that it is on top and uses absolute positioning. I then found the resizeEvent so that I can manually set the position to the right hand side based on the new widget size. I'm not sure if this is the best solution available, but it seems to be doing what I was looking for.Thanks for the help!
-