我是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)