我们试图在主窗口部件上放置滚动条,因此如果用户调整主窗口的大小,滚动条就会出现,并让他上下移动以查看较小窗口部件之外的子部件,从而允许其左右移动。
这是带有滚动条的主小部件的代码。
def centralWDG(self,MainWindow):
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.summaryBox = QtGui.QGroupBox("Project Management Layout")
self.summaryBox.setMinimumHeight(300)
self.summaryBox.setMinimumWidth(500)
self.summaryBoxScroll = QtGui.QScrollArea()
self.summaryBoxScroll.setFrameStyle(QtGui.QFrame.NoFrame)
self.summaryBoxTopLayout = QtGui.QVBoxLayout(self.summaryBox)
self.summaryBoxTopLayout.setContentsMargins(1,1,1,1)
self.summaryBoxTopLayout.addWidget(self.summaryBoxScroll)
self.summaryBoxScroll.setWidget(self.centralwidget)
self.summaryBoxLayout = QtGui.QFormLayout()
self.summaryBoxLayout.setSpacing(1)
self.summaryBoxLayout.setSizeConstraint(QtGui.QLayout.SetFixedSize)
self.summaryBoxLayout = QtGui.QFormLayout(self.centralwidget)
self.summaryBoxLayout.setSpacing(1)
self.summaryBoxLayout.setSizeConstraint(QtGui.QLayout.SetMinAndMaxSize)
self.callchildGUIs()
MainWindow.setCentralWidget(self.centralwidget)
系统已启动,所有 GUI 都工作正常,但滚动条不显示,即使我们将窗口大小调整到很小的尺寸也没关系。那么,这里缺少什么?
高度赞赏所有意见和建议。
You use centralWidget
(这是一个QWidget
)作为主窗口的中央小部件,滚动区域永远不会添加到窗口中。让它包含中央小部件是不够的。
以下代码是由以下代码生成的pyuic
:
def setupUi(self, MainWindow):
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.verticalLayout = QtGui.QVBoxLayout(self.centralwidget)
self.verticalLayout.setObjectName("verticalLayout")
self.scrollArea = QtGui.QScrollArea(self.centralwidget)
self.scrollArea.setWidgetResizable(True)
self.scrollArea.setObjectName("scrollArea")
self.scrollArea.setWidget(self.scrollAreaWidgetContents)
self.verticalLayout.addWidget(self.scrollArea)
self.scrollAreaWidgetContents = QtGui.QWidget(self.scrollArea)
self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 778, 527))
self.scrollAreaWidgetContents.setObjectName("scrollAreaWidgetContents")
self.verticalLayout_2 = QtGui.QVBoxLayout(self.scrollAreaWidgetContents)
self.verticalLayout_2.setObjectName("verticalLayout_2")
MainWindow.setCentralWidget(self.centralwidget)
滚动区域被添加到中央小部件的布局中,并具有自己的内容小部件。如果您将控件添加到verticalLayout_2
(and scrollAreaWidgetContents
作为父小部件),它们将收到滚动条。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)