小编Flo*_*raf的帖子

PYQT - 在多个级别嵌套小部件和布局

我是pyqt的新手并试图创建一组嵌套容器来保存我的控件.我找不到任何嵌套小部件的例子(并保持它们的布局).我只能嵌套布局,但这不是我想要实现的.我想这样做的一个原因是对我的容器的backgroundcolor进行控制.由于布局没有颜色,我想我需要QWidgets或QFrame.这是我走了多远:

class AssetCreationWindow(QtWidgets.QMainWindow):
    def __init__(self):
        super(AssetCreationWindow, self).__init__()
        self.create_content()
        self.show()

    def create_content(self):

    # creating main container-frame, parent it to QWindow
        self.main_CF = QtWidgets.QFrame(self)
        self.main_CF.setStyleSheet('background-color: rgba(255, 0, 0, 1);')
        self.setCentralWidget(self.main_CF)
    # creating layout and parent it to main container
    # is it correct, that main_CL now manages children of main_CF ?
        self.main_CL = QtWidgets.QVBoxLayout(self.main_CF)

    # creating the first subcontainer + layout, parenting it
        asset_CGF = QtWidgets.QFrame(self.main_CF)
        asset_CGF.setStyleSheet('background-color: rgba(0, 255, 0, 1);')
        asset_CGL = QtWidgets.QHBoxLayout(asset_CGF)

    # creating label and lineEdit, both are supposed …
Run Code Online (Sandbox Code Playgroud)

python pyqt pyqt5

5
推荐指数
1
解决办法
4901
查看次数

标签 统计

pyqt ×1

pyqt5 ×1

python ×1