基于像素数的分屏
splitting screen based on number of pixels
所以我正在尝试使用 PyQt5 创建一个 GUI,我需要像下面这样拆分我的 GUI,数字是像素
我正在尝试以特定像素值开始特定 windows 并保持这种状态,即使我拉伸 window 我希望 windows 停留在特定位置并保持静止相同的大小。所以差不多windows不换不动
我正在尝试使用 QSplitter 函数,但我找不到任何选项使其从特定像素值开始并保持不变
from PyQt5.QtWidgets import (QWidget, QHBoxLayout, QFrame,
QSplitter, QStyleFactory, QApplication)
from PyQt5.QtCore import Qt
import sys
class Example(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
hbox = QHBoxLayout(self)
topleft = QFrame(self)
topleft.setFrameShape(QFrame.StyledPanel)
topright = QFrame(self)
topright.setFrameShape(QFrame.StyledPanel)
bottom = QFrame(self)
bottom.setFrameShape(QFrame.StyledPanel)
splitter1 = QSplitter(Qt.Horizontal)
splitter1.addWidget(topleft)
splitter1.addWidget(topright)
splitter2 = QSplitter(Qt.Vertical)
splitter2.addWidget(splitter1)
splitter2.addWidget(bottom)
hbox.addWidget(splitter2)
self.setLayout(hbox)
self.setGeometry(300, 300, 300, 200)
self.setWindowTitle('QSplitter')
self.show()
IIUC 你希望 QFrame 的大小和位置固定,如果是那么你不应该使用 QSplitter 但必须使用 move 来设置位置和 setFixedSize 来设置大小:
from PyQt5 import QtCore, QtWidgets
class Example(QtWidgets.QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
f1 = self.create_qframe(QtCore.QPoint(10, 10), QtCore.QSize(640, 480))
f2 = self.create_qframe(QtCore.QPoint(10, 500), QtCore.QSize(640, 480))
f3 = self.create_qframe(QtCore.QPoint(660, 10), QtCore.QSize(320, 240))
f4 = self.create_qframe(QtCore.QPoint(990, 10), QtCore.QSize(320, 240))
f5 = self.create_qframe(QtCore.QPoint(660, 260), QtCore.QSize(320, 230))
f6 = self.create_qframe(QtCore.QPoint(990, 260), QtCore.QSize(320, 230))
f7 = self.create_qframe(QtCore.QPoint(660, 500), QtCore.QSize(320, 240))
f8 = self.create_qframe(QtCore.QPoint(990, 500), QtCore.QSize(320, 240))
f9 = self.create_qframe(QtCore.QPoint(660, 750), QtCore.QSize(320, 230))
f10 = self.create_qframe(QtCore.QPoint(990, 750), QtCore.QSize(320, 230))
self.setMinimumSize(1320, 990)
# or self.setFixedSize(1320, 990)
def create_qframe(self, pos, size):
frame = QtWidgets.QFrame(self, frameShape=QtWidgets.QFrame.StyledPanel)
frame.move(pos)
frame.setFixedSize(size)
return frame
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
app.setStyle("fusion")
w = Example()
w.show()
sys.exit(app.exec_())
所以我正在尝试使用 PyQt5 创建一个 GUI,我需要像下面这样拆分我的 GUI,数字是像素
我正在尝试以特定像素值开始特定 windows 并保持这种状态,即使我拉伸 window 我希望 windows 停留在特定位置并保持静止相同的大小。所以差不多windows不换不动
我正在尝试使用 QSplitter 函数,但我找不到任何选项使其从特定像素值开始并保持不变
from PyQt5.QtWidgets import (QWidget, QHBoxLayout, QFrame,
QSplitter, QStyleFactory, QApplication)
from PyQt5.QtCore import Qt
import sys
class Example(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
hbox = QHBoxLayout(self)
topleft = QFrame(self)
topleft.setFrameShape(QFrame.StyledPanel)
topright = QFrame(self)
topright.setFrameShape(QFrame.StyledPanel)
bottom = QFrame(self)
bottom.setFrameShape(QFrame.StyledPanel)
splitter1 = QSplitter(Qt.Horizontal)
splitter1.addWidget(topleft)
splitter1.addWidget(topright)
splitter2 = QSplitter(Qt.Vertical)
splitter2.addWidget(splitter1)
splitter2.addWidget(bottom)
hbox.addWidget(splitter2)
self.setLayout(hbox)
self.setGeometry(300, 300, 300, 200)
self.setWindowTitle('QSplitter')
self.show()
IIUC 你希望 QFrame 的大小和位置固定,如果是那么你不应该使用 QSplitter 但必须使用 move 来设置位置和 setFixedSize 来设置大小:
from PyQt5 import QtCore, QtWidgets
class Example(QtWidgets.QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
f1 = self.create_qframe(QtCore.QPoint(10, 10), QtCore.QSize(640, 480))
f2 = self.create_qframe(QtCore.QPoint(10, 500), QtCore.QSize(640, 480))
f3 = self.create_qframe(QtCore.QPoint(660, 10), QtCore.QSize(320, 240))
f4 = self.create_qframe(QtCore.QPoint(990, 10), QtCore.QSize(320, 240))
f5 = self.create_qframe(QtCore.QPoint(660, 260), QtCore.QSize(320, 230))
f6 = self.create_qframe(QtCore.QPoint(990, 260), QtCore.QSize(320, 230))
f7 = self.create_qframe(QtCore.QPoint(660, 500), QtCore.QSize(320, 240))
f8 = self.create_qframe(QtCore.QPoint(990, 500), QtCore.QSize(320, 240))
f9 = self.create_qframe(QtCore.QPoint(660, 750), QtCore.QSize(320, 230))
f10 = self.create_qframe(QtCore.QPoint(990, 750), QtCore.QSize(320, 230))
self.setMinimumSize(1320, 990)
# or self.setFixedSize(1320, 990)
def create_qframe(self, pos, size):
frame = QtWidgets.QFrame(self, frameShape=QtWidgets.QFrame.StyledPanel)
frame.move(pos)
frame.setFixedSize(size)
return frame
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
app.setStyle("fusion")
w = Example()
w.show()
sys.exit(app.exec_())