【发布时间】:2018-10-12 03:24:30
【问题描述】:
我希望我的窗口具有这种布局:
图表将来自 matplotlib。 我想要一种动态创建此布局的方法,以便它适合任何大小的屏幕,而无需更改基本布局。我该怎么做呢?这是我到目前为止所得到的:
import sys
from PyQt5.QtWidgets import (QWidget, QPushButton,
QHBoxLayout, QVBoxLayout, QApplication, QFrame, QScrollArea, QListWidget, QListWidgetItem, QLabel)
class Example(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
#top left downwards
vbox = QVBoxLayout()
vbox.addStretch(1)
hbox = QHBoxLayout()
hbox.addStretch(1)
hbox.addLayout(vbox)
hbox.setDirection(1)
self.setLayout(hbox)
qlist = QListWidget()
hbox.addWidget(qlist)
for i in range(0,31):
qlist.addItem(str(i))
qlist.setFrameStyle(QFrame.Raised)
vbox2 = QVBoxLayout()
vbox2.addStretch()
graph = QFrame(self)
graph.setStyleSheet("QWidget { background-color: red }" )
vbox2.addWidget(graph)
graph.setFrameShape(1)
self.setStyleSheet("font: 20pt Cambria")
self.showMaximized()
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
这给了我这个:
有人知道怎么做吗?我是 PyQt5 的新手,在查看多个示例后不确定盒子布局如何工作。有没有更简单的方法可以在不影响布局的情况下做到这一点? 谢谢!
【问题讨论】:
-
你说:图表将来自 matplotlib。我想要一种动态创建此布局的方法我没有看到任何来自 matplolib 的代码
标签: python python-3.x pyqt pyqt5