QPainter::begin:绘画设备返回引擎 == 0,类型:0
QPainter::begin: Paint device returned engine == 0, type: 0
我开始观看 Python 和 QT (https://www.youtube.com/watch?v=Eq7__6y0jwo&index=3&list=PL19DCiIwVefyQxlDTWlXQ4lnZDPW6_r-q) 的一些教程,但我收到此错误 "QPainter::begin: Paint device returned engine == 0, type: 0",我不明白为什么。我的想法是,我想要一个 window 可以在 3dsMax、Modo 中工作,也可以作为独立的(3dsMax 和 Modo 都带有 PySide)。
有什么想法吗?
代码如下:
from PySide import QtCore, QtGui
import sys
class PaletteListModel (QtCore.QAbstractListModel):
def __init__(self, colors=[], parent=None):
QtCore.QAbstractListModel.__init__(self, parent)
self._colors = colors
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
listView = QtGui.QListView()
listView.show()
red = QtGui.QColor(255, 0, 0)
green = QtGui.QColor(0, 255, 0)
blue = QtGui.QColor(0, 0, 255)
model = PaletteListModel([red, green, blue])
listView.setModel(model)
sys.exit(app.exec_())
谢谢,
尼克
我在您的代码中看到的唯一错误是您继承自 QAbstractListModel 而未实现抽象方法。
来自此处的文档:http://doc.qt.io/qt-5/qabstractlistmodel.html#details
When subclassing QAbstractListModel, you must provide implementations
of the rowCount() and data() functions. Well behaved models also
provide a headerData() implementation.
是否遗漏了任何代码?你创建过 QPainter 对象吗?
我开始观看 Python 和 QT (https://www.youtube.com/watch?v=Eq7__6y0jwo&index=3&list=PL19DCiIwVefyQxlDTWlXQ4lnZDPW6_r-q) 的一些教程,但我收到此错误 "QPainter::begin: Paint device returned engine == 0, type: 0",我不明白为什么。我的想法是,我想要一个 window 可以在 3dsMax、Modo 中工作,也可以作为独立的(3dsMax 和 Modo 都带有 PySide)。
有什么想法吗?
代码如下:
from PySide import QtCore, QtGui
import sys
class PaletteListModel (QtCore.QAbstractListModel):
def __init__(self, colors=[], parent=None):
QtCore.QAbstractListModel.__init__(self, parent)
self._colors = colors
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
listView = QtGui.QListView()
listView.show()
red = QtGui.QColor(255, 0, 0)
green = QtGui.QColor(0, 255, 0)
blue = QtGui.QColor(0, 0, 255)
model = PaletteListModel([red, green, blue])
listView.setModel(model)
sys.exit(app.exec_())
谢谢,
尼克
我在您的代码中看到的唯一错误是您继承自 QAbstractListModel 而未实现抽象方法。
来自此处的文档:http://doc.qt.io/qt-5/qabstractlistmodel.html#details
When subclassing QAbstractListModel, you must provide implementations of the rowCount() and data() functions. Well behaved models also provide a headerData() implementation.
是否遗漏了任何代码?你创建过 QPainter 对象吗?