PyQt5 绝对位置
PyQt5 支持多种布局方法,如网格布局,水平布局和绝对定位。你应该选择的布局取决于你的偏好和应用类型。
PyQt5 绝对位置定位
绝对定位使你可以完全控制窗口小控件位置,但必须明确定义每个窗口小控件位置。
可以使用 move(x,y)
方法将小控件添加到绝对位置。

PyQt5 小控件定位示例
下面的示例使用 move()
方法将小控件放在绝对位置上。
它们被添加到 PyQT5 窗口(QMainWindow)中,该窗口具有在 initUI()
中设置的一些属性。
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QMainWindow, QLabel
from PyQt5.QtGui import QIcon
class App(QMainWindow):
def __init__(self):
super().__init__()
self.title = 'PyQt absolute positioning - tastones.com'
self.left = 10
self.top = 10
self.width = 440
self.height = 280
self.initUI()
def initUI(self):
self.setWindowTitle(self.title)
self.setGeometry(self.left, self.top, self.width, self.height)
label = QLabel('Python', self)
label.move(50,50)
label2 = QLabel('PyQt5', self)
label2.move(100,100)
label3 = QLabel('Examples', self)
label3.move(150,150)
label4 = QLabel('pytonspot.com', self)
label4.move(200,200)
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = App()
sys.exit(app.exec_())