所以当我尝试向MainWindow添加布局时self.mainLayout = QtWidgets.QVBoxLayout(self.MainWindow)
我收到此错误:QLayout: Attempting to add QLayout "" to QMainWindow "MainWindow", which already has a layout
如何获取默认布局?有可能吗?
正如其他人的回答,QMainWindow
有其自己的布局。
但是,如果您想将固定大小的窗口小部件添加到主窗口的中央窗口小部件,可能可以使用要添加到中央窗口小部件的窗口小部件的setFixedSize
方法。
示例:
centralWidget = QtGui.QWidget(self)
layout = QtGui.QHBoxLayout(centralWidget)
#Set the fixed size
anotherWidgetOne.setFixedSize(20,20)
#Add other widgets to the central widget
layout.addWidget(self.anotherWidgetOne)
#Set the central widget
self.setCentralWidget(self.centralWidget)