How to overlap an image with a label
-
Hi and welcome to devnet,
Depending on what your goal is, you can render the image on the widget that you set the layout on.
In any case, you have to provide more details about what you want to get at the end.
-
Hi and welcome to devnet,
Depending on what your goal is, you can render the image on the widget that you set the layout on.
In any case, you have to provide more details about what you want to get at the end.
-
@SGaist
I have an image of an electronic diagram inside a label that is in a layout, I want to position labels overlapping this image of the diagram (the objective is to leave the labels on top of each valve and sensor)You can simply position the
parentlesslayoutless labels using fixed coordinates.
Maybe you need some kind of anchor to lock them in place when the rest resizes or moves, so that the labels are still where they should be -
You can simply position the
parentlesslayoutless labels using fixed coordinates.
Maybe you need some kind of anchor to lock them in place when the rest resizes or moves, so that the labels are still where they should be@Pl45m4 said in How to overlap an image with a label:
You can simply position the parentless labels using fixed coordinates.
Is
parentless
a typo? The overlaying labels need to have a parent to avoid turning them into windows. The easiest solution I can think of is to parent the text labels to the image label. This can be done with a layout set on the background label, or through direct positioning.QLabel background("___\n___\n___"); QLabel foreground("X", &background); foreground.move(10, 10); QHBoxLayout layout(&background); QLabel layoutForeground("0"); layout.addWidget(&layoutForeground); background.show();
It may be worth considering doing this with the graphics view framework instead.
-
@Pl45m4 said in How to overlap an image with a label:
You can simply position the parentless labels using fixed coordinates.
Is
parentless
a typo? The overlaying labels need to have a parent to avoid turning them into windows. The easiest solution I can think of is to parent the text labels to the image label. This can be done with a layout set on the background label, or through direct positioning.QLabel background("___\n___\n___"); QLabel foreground("X", &background); foreground.move(10, 10); QHBoxLayout layout(&background); QLabel layoutForeground("0"); layout.addWidget(&layoutForeground); background.show();
It may be worth considering doing this with the graphics view framework instead.
@jeremy_k said in How to overlap an image with a label:
Is parentless a typo? The overlaying labels need to have a parent to avoid turning them into windows.
Ah... somehow I was thinking "not in a layout" and wrote "no parent" :D
Yeah, better add the widget, on which they are hovering as parent, so they "inherit" its coordinate system. -
You can simply position the
parentlesslayoutless labels using fixed coordinates.
Maybe you need some kind of anchor to lock them in place when the rest resizes or moves, so that the labels are still where they should be@Pl45m4 I used labels with fixed coordinates and its worked, what do you mean by anchor lock? Its an expression? I’m not native speaker.
Im really getting trouble to adjust the labels coordinates and sizes. Im trying to make simple rule of three based on size proportions of the screen