gpt4 book ai didi

python - QRectF 没有出现在我的 QGraphicsScene 中

转载 作者:行者123 更新时间:2023-11-28 22:11:41 27 4
gpt4 key购买 nike

我正在尝试使用 QGraphicsView(在 Maya 中)并获得一些代码,我将在下面粘贴这些代码。问题是带有 QGraphicsView 的窗口出现了,但看起来 QGraphicsScene(带有我的 QRectF)没有出现。我仍然对继承的工作方式感到困惑,所以有人可以指出我哪里做错了。谢谢。

from PySide2 import QtGui, QtCore, QtWidgets
from shiboken2 import wrapInstance
import maya.OpenMaya as om
import maya.OpenMayaUI as omui
import maya.cmds as cmds
import os, functools


def getMayaWindow():
pointer = omui.MQtUtil.mainWindow()
if pointer is not None:
return wrapInstance(long(pointer), QtWidgets.QWidget)


class testUi(QtWidgets.QDialog):
def __init__(self, parent=None):
if parent is None:
parent = getMayaWindow()
super(testUi, self).__init__(parent)
self.window = 'vl_test'
self.title = 'Test Remastered'
self.size = (1000, 650)

self.create()

def create(self):
if cmds.window(self.window, exists=True):
cmds.deleteUI(self.window, window=True)

self.setWindowTitle(self.title)
self.resize(QtCore.QSize(*self.size))
self.testik = test(self)

self.mainLayout = QtWidgets.QVBoxLayout()
self.mainLayout.addWidget(self.testik)
self.setLayout(self.mainLayout)


class test(QtWidgets.QGraphicsView):

def __init__(self, parent=None):
super(test, self).__init__(parent)

self._scene = QtWidgets.QGraphicsScene()
rect_item = QtWidgets.QGraphicsRectItem(QtCore.QRectF(0, 0, 100, 100))
rect_item.setFlag(QtWidgets.QGraphicsItem.ItemIsMovable, True)
self._scene.addItem(rect_item)

v = testUi()
v.show()

最佳答案

问题是您还没有将 QGraphicsScene 添加到 QGraphicsView:

class test(QtWidgets.QGraphicsView):
def __init__(self, parent=None):
super(test, self).__init__(parent)
self._scene = QtWidgets.QGraphicsScene()
self.setScene(self._scene) # <---
rect_item = QtWidgets.QGraphicsRectItem(QtCore.QRectF(0, 0, 100, 100))
rect_item.setFlag(QtWidgets.QGraphicsItem.ItemIsMovable, True)
self._scene.addItem(rect_item)

关于python - QRectF 没有出现在我的 QGraphicsScene 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55509202/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com