How to place radiobuttons inside a map through PyQt5?
-
I have a window that has a label in the center that contains a certain part of a map. I'm planning to add radio buttons in certain parts of it do that when clicked on, it'll show small information about that place. Howecer, ai'm not sure how I can set it up. I'm using QT Designer to design the window and the language of my choice is Python 3.11.
-
Hi,
If the map is a simple image, you can place the QRadioButton on top of it not placing them in a layout. However, you will have to manual move them upon window resize.
-
@Rangerguy128
If you add the buttons with the label as the parent you are saying they appear under the label?
OIC, you mean below the image on the label? Did you try moving their coordinates? -
@Rangerguy128
Your label does not have a layout, right? You add the radiobutton directly onto the label? Then I know you can use QWidget::move() in code. Does Qt Designer have something like anx
andy
position property for widgets? -
You have placed the radio buttons in the layout of the widget that contains the QLabel image. Widgets in a layout are positioned at run time by the layout logic and will not overlap. If you want to position a QRadiobutton visibly on top of another widget (i.e on top of the QLabel image of Puerto Rico beach) then:
- The parent widget of the QRadioButtons should be the QLabel. This ensures the on-top-of element but cannot easily be achieved in Designer because it does not consider QLabel a container.
- The QRadioButtons cannot be in a layout.
- Positioning the buttons is absolute and you are responsible for adjusting it if the label is resized.
It can be achieved with a bit of code. Either:
- Put the QRadioButtions into the Designer UI layout then, in the form widget code after calling setupUI(), change their parentage and position (which will be relative to the label content area).
- Leave the QRadioButtons out of the Designer UI then create and position the radio buttons after setupUI()
- Build the whole UI in code.