如何显示QGraphicsScene?
我有以下代码,但我不确定如何将 QGraphicsScene 添加到我的布局中。
class MainForm(QDialog):
def __init__(self, parent=None):
super(MainForm, self).__init__(parent)
self.scene = QGraphicsScene(self)
self.scene.setSceneRect(0, 0, 500, 500)
self.view = QGraphicsView()
self.view.setRenderHint(QPainter.Antialiasing)
self.view.setScene(self.scene)
self.view.setFocusPolicy(Qt.NoFocus)
zoomSlider = QSlider(Qt.Horizontal)
zoomSlider.setRange(5, 200)
zoomSlider.setValue(100)
self.pauseButton = QPushButton("Pause")
quitButton = QPushButton("Quit")
layout = QVBoxLayout()
layout.addWidget(zoomSlider)
self.setLayout(layout)
self.startTimer(10)
如何让我的 QGraphicsScene 运行?我是 Qt 新手。我是否应该将 QGraphicsScene 添加到布局/
I've got the following code and I'm not sure how to add the QGraphicsScene to my layout..
class MainForm(QDialog):
def __init__(self, parent=None):
super(MainForm, self).__init__(parent)
self.scene = QGraphicsScene(self)
self.scene.setSceneRect(0, 0, 500, 500)
self.view = QGraphicsView()
self.view.setRenderHint(QPainter.Antialiasing)
self.view.setScene(self.scene)
self.view.setFocusPolicy(Qt.NoFocus)
zoomSlider = QSlider(Qt.Horizontal)
zoomSlider.setRange(5, 200)
zoomSlider.setValue(100)
self.pauseButton = QPushButton("Pause")
quitButton = QPushButton("Quit")
layout = QVBoxLayout()
layout.addWidget(zoomSlider)
self.setLayout(layout)
self.startTimer(10)
How can I get my QGraphicsScene running? I'm new to Qt. Am I even supposed to be adding a QGraphicsScene to a layout/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你必须做这样的事情:
You'll have to do something like this:
您已经添加了要查看的场景,这就足够了。但是您应该将视图添加到 MainForm 和布局中。视图是一种可以由应用程序显示的小部件,而场景不是小部件,不能添加到布局中,它是视图的组件。此外,您可能需要向场景添加一些图形项(例如矩形、图像)并查看其工作原理。
You have added a scene to view, and it's enough. But you should add the view to your MainForm and Layout. View is a kind of widget that can be displayed by your application, while scene is not a widget and cannot be added to layout, it's a component of view. In addition, you may need to add some graphics items(e.g. rectangle, image) to scene and see how it works.