How can I put the RadioBoxes over the Layout?

54 views Asked by At

I designed the following window. However, when running the code, the RadioBoxes stay behind the layout that contains the frame and the string. Could someone please tell me how to avoid this?

from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
import sys

class Window(QWidget):
    
    def __init__(self): 
        super().__init__()
  
        self.setWindowTitle('Window')
        self.setFixedSize(550,440)
        self.LaySelf = QGridLayout()

        self.initWidgets()
        self.initUI()

        self.show()

    def initWidgets(self):

        self.Panel = QFrame()
        self.Panel.setFrameStyle(QFrame.StyledPanel)
        self.Panel.setLineWidth(2)
        self.Panel.setStyleSheet('background-color:#f4f2f1')

        self.Btt = QRadioButton('Radio',self)

        self.Label = QLabel(' '*40+'Hi')

    def initUI(self):

        self.LaySelf.addWidget(self.Panel,0,0,-1,6)
        self.LaySelf.addWidget(self.Label,0,0,-1,6)

        self.setLayout(self.LaySelf)

        self.Btt.move(200,200)

App = QApplication(sys.argv) 
window = Window()
sys.exit(App.exec())
1

There are 1 answers

0
BlueGhost On

In order to make radio button on top of QFrame you need to add it to the Frame. Currently the Radio Buttons stay behind Frame which is covering the layout.

Replace QRadioButton('Radio',self) with QRadioButton('Radio',self.Panel)

Also here is a link to another thread which demostrates Frame Usage with multiple QWidgets