【问题标题】:How can I put the RadioBoxes over the Layout?如何将 RadioBoxes 放在布局上?
【发布时间】:2020-11-23 17:04:10
【问题描述】:

我设计了以下窗口。但是,在运行代码时,RadioBoxes 停留在包含框架和字符串的布局后面。有人可以告诉我如何避免这种情况吗?

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())

【问题讨论】:

    标签: layout pyqt pyqt5 qradiobutton


    【解决方案1】:

    为了在QFrame 上制作单选按钮,您需要将其添加到框架中。目前,单选按钮位于覆盖布局的 Frame 后面。

    将 QRadioButton('Radio',self) 替换为 QRadioButton('Radio',self.Panel)

    这里还有一个链接到另一个线程,该线程使用多个 QWidget 演示 Frame Usage

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-29
      • 2013-10-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多