Python PYQT 布局和 setgeometry 基本概述
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32787868/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PYQT layout and setgeometry basic overview
提问by Anekdotin
Im trying to get my qsplitlines to set to a basic shape upon startup of my program. I have been playing around with the 4 numbers in setgerometry(x, x, x, x) Could I get a simple explanation of what they correlate too?
我试图在我的程序启动时让我的 qsplitlines 设置为基本形状。我一直在玩 setgerometry(x, x, x, x) 中的 4 个数字,我也能简单解释一下它们的相关性吗?
From top, ?, From left, ?
从顶部,?,从左侧,?
(down starting from top, from left, continuing, how many rows it spas across)
(从顶部开始向下,从左侧开始,继续,它跨越了多少行)
hbox = QtGui.QHBoxLayout(self)
topleft = QtGui.QFrame(self)
topleft.setFrameShape(QtGui.QFrame.StyledPanel)
topleft.setGeometry(0, 0, 300, 0)
topright = QtGui.QFrame(self)
topright.setFrameShape(QtGui.QFrame.StyledPanel)
topright.setGeometry(0, 320, 1000, 0)
bottom = QtGui.QFrame(self)
bottom.setFrameShape(QtGui.QFrame.StyledPanel)
bottom.setGeometry(1210, 0, 1280, 0)
splitter1 = QtGui.QSplitter(QtCore.Qt.Horizontal)
splitter1.addWidget(topleft)
splitter1.addWidget(topright)
splitter2 = QtGui.QSplitter(QtCore.Qt.Vertical)
splitter2.addWidget(splitter1)
splitter2.addWidget(bottom)
hbox.addWidget(splitter2)
self.setLayout(hbox)
#QtGui.QApplication.setStyle(QtGui.QStyleFactory.create('Cleanlooks'))
采纳答案by Andy
I'm going to show you how to walk through the documentation before the answer at the bottom. It'll help you in the long run.
在底部的答案之前,我将向您展示如何浏览文档。从长远来看,它会帮助你。
Start with the QFrame
documentation. You are looking for a setGeometry
method. You'll notice that there isn't one, but the QFrame does inherit from the QWidget
从QFrame
文档开始。您正在寻找一种setGeometry
方法。你会注意到没有,但 QFrame 确实继承自QWidget
Going to the QWidget
documentation you'll find that there is are two setGeometry
methods
转到QWidget
文档,您会发现有两种setGeometry
方法
QWidget.setGeometry (self, QRect)
and
和
QWidget.setGeometry (self, int ax, int ay, int aw, int ah)
The first one takes a QRect
and the second takes series of integers. Let's look at the QRect
docs too:
第一个需要 a QRect
,第二个需要一系列整数。让我们也看看QRect
文档:
A QRect can be constructed with a set of left, top, width and height integers
QRect 可以由一组左、上、宽和高整数构成
This lines up with the series of integers the other method takes. This image from the Qt Documentationhelps explain it:
这与其他方法采用的整数系列对齐。Qt 文档中的这张图片有助于解释它:
Thus, your integers are:
因此,您的整数是:
- X coordinate
- Y coordinate
- Width of the frame
- Height of the frame
- X坐标
- Y坐标
- 框架宽度
- 框架高度