我正在尝试为我的应用制作布局。我在Qt Designer中设计了它,在预览中一切看起来都正确。但是当我运行代码时,进度条侧被切断。
我想我需要玩尺寸政策或其他什么?这是实际代码(进度条为RoundPrg1
):
def setupUi(self, MainWindow):
MainWindow.setObjectName(_fromUtf8("MainWindow"))
MainWindow.resize(800, 600)
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
self.gridLayout_2 = QtGui.QGridLayout(self.centralwidget)
self.gridLayout_2.setObjectName(_fromUtf8("gridLayout_2"))
self.gridLayout = QtGui.QGridLayout()
self.gridLayout.setObjectName(_fromUtf8("gridLayout"))
self.MainVarsLayout = QtGui.QHBoxLayout()
self.MainVarsLayout.setSizeConstraint(QtGui.QLayout.SetDefaultConstraint)
self.MainVarsLayout.setMargin(10)
self.MainVarsLayout.setSpacing(10)
self.MainVarsLayout.setObjectName(_fromUtf8("MainVarsLayout"))
#self.speedBarplace = QtGui.QPushButton(self.centralwidget)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(2)
#sizePolicy.setHeightForWidth(self.speedBarplace.sizePolicy().hasHeightForWidth())
#self.speedBarplace.setSizePolicy(sizePolicy)
#self.speedBarplace.setMinimumSize(QtCore.QSize(300, 270))
#self.speedBarplace.setObjectName(_fromUtf8("speedBarplace"))
self.MainVarsLayout.addWidget(self.RoundPrg)#(self.speedBarplace)
self.MainVariablesLayout = QtGui.QVBoxLayout()
self.MainVariablesLayout.setObjectName(_fromUtf8("MainVariablesLayout"))
self.temperaturePlace = QtGui.QPushButton(self.centralwidget)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(2)
sizePolicy.setHeightForWidth(self.temperaturePlace.sizePolicy().hasHeightForWidth())
self.temperaturePlace.setSizePolicy(sizePolicy)
self.temperaturePlace.setMinimumSize(QtCore.QSize(0, 130))
self.temperaturePlace.setObjectName(_fromUtf8("temperaturePlace"))
self.MainVariablesLayout.addWidget(self.temperaturePlace)
self.fuelPlace = QtGui.QPushButton(self.centralwidget)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(2)
sizePolicy.setHeightForWidth(self.fuelPlace.sizePolicy().hasHeightForWidth())
self.fuelPlace.setSizePolicy(sizePolicy)
self.fuelPlace.setMinimumSize(QtCore.QSize(0, 130))
self.fuelPlace.setObjectName(_fromUtf8("fuelPlace"))
self.MainVariablesLayout.addWidget(self.fuelPlace)
self.MainVarsLayout.addLayout(self.MainVariablesLayout)
#self.rpmPlace = QtGui.QPushButton(self.centralwidget)
#sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Minimum)
#sizePolicy.setHorizontalStretch(0)
#sizePolicy.setVerticalStretch(2)
#sizePolicy.setHeightForWidth(self.rpmPlace.sizePolicy().hasHeightForWidth())
#self.rpmPlace.setSizePolicy(sizePolicy)
#self.rpmPlace.setMinimumSize(QtCore.QSize(300, 270))
#self.rpmPlace.setObjectName(_fromUtf8("rpmPlace"))
self.MainVarsLayout.addWidget(self.RoundPrg2)#(self.rpmPlace)
self.gridLayout.addLayout(self.MainVarsLayout, 1, 0, 1, 1)
self.InfoLayout = QtGui.QHBoxLayout()
self.InfoLayout.setSizeConstraint(QtGui.QLayout.SetFixedSize)
self.InfoLayout.setObjectName(_fromUtf8("InfoLayout"))
self.pushButton_2 = QtGui.QPushButton(self.centralwidget)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.pushButton_2.sizePolicy().hasHeightForWidth())
self.pushButton_2.setSizePolicy(sizePolicy)
self.pushButton_2.setObjectName(_fromUtf8("pushButton_2"))
self.InfoLayout.addWidget(self.pushButton_2)
self.pushButton_3 = QtGui.QPushButton(self.centralwidget)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.pushButton_3.sizePolicy().hasHeightForWidth())
self.pushButton_3.setSizePolicy(sizePolicy)
self.pushButton_3.setObjectName(_fromUtf8("pushButton_3"))
self.InfoLayout.addWidget(self.pushButton_3)
self.pushButton_4 = QtGui.QPushButton(self.centralwidget)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.pushButton_4.sizePolicy().hasHeightForWidth())
self.pushButton_4.setSizePolicy(sizePolicy)
self.pushButton_4.setObjectName(_fromUtf8("pushButton_4"))
self.InfoLayout.addWidget(self.pushButton_4)
self.pushButton = QtGui.QPushButton(self.centralwidget)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.pushButton.sizePolicy().hasHeightForWidth())
self.pushButton.setSizePolicy(sizePolicy)
self.pushButton.setObjectName(_fromUtf8("pushButton"))
self.InfoLayout.addWidget(self.pushButton)
self.ComputerInfoLayout = QtGui.QVBoxLayout()
self.ComputerInfoLayout.setObjectName(_fromUtf8("ComputerInfoLayout"))
self.PcuTempBar = QtGui.QProgressBar(self.centralwidget)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.PcuTempBar.sizePolicy().hasHeightForWidth())
self.PcuTempBar.setSizePolicy(sizePolicy)
self.PcuTempBar.setMinimumSize(QtCore.QSize(0, 0))
self.PcuTempBar.setProperty("value", 24)
self.PcuTempBar.setObjectName(_fromUtf8("PcuTempBar"))
self.ComputerInfoLayout.addWidget(self.PcuTempBar)
self.CpuUsageBar = QtGui.QProgressBar(self.centralwidget)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.CpuUsageBar.sizePolicy().hasHeightForWidth())
self.CpuUsageBar.setSizePolicy(sizePolicy)
self.CpuUsageBar.setMinimumSize(QtCore.QSize(0, 0))
self.CpuUsageBar.setProperty("value", 24)
self.CpuUsageBar.setObjectName(_fromUtf8("CpuUsageBar"))
self.ComputerInfoLayout.addWidget(self.CpuUsageBar)
self.RamUsag[eBar = QtGui.QProgressBar(self.centralwidget)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.RamUsageBar.sizePolicy().hasHeightForWidth())
self.RamUsageBar.setSizePolicy(sizePolicy)
self.RamUsageBar.setMinimumSize(QtCore.QSize(0, 0))
self.RamUsageBar.setProperty("value", 24)
self.RamUsageBar.setObjectName(_fromUtf8("RamUsageBar"))
self.ComputerInfoLayout.addWidget(self.RamUsageBar)
self.InfoLayout.addLayout(self.ComputerInfoLayout)
self.gridLayout.addLayout(self.InfoLayout, 3, 0, 1, 1)
self.horizontalLayout = QtGui.QHBoxLayout()
self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))
self.pushButton_5 = QtGui.QPushButton(self.centralwidget)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.pushButton_5.sizePolicy().hasHeightForWidth())
self.pushButton_5.setSizePolicy(sizePolicy)
self.pushButton_5.setObjectName(_fromUtf8("pushButton_5"))
self.horizontalLayout.addWidget(self.pushButton_5)
self.gridLayout.addLayout(self.horizontalLayout, 2, 0, 1, 1)
self.gridLayout_2.addLayout(self.gridLayout, 0, 0, 1, 1)
MainWindow.setCentralWidget(self.centralwidget)