2016-06-09 32 views
0

我開始看Python和QT的一些教程(https://www.youtube.com/watch?v=Eq7__6y0jwo&index=3&list=PL19DCiIwVefyQxlDTWlXQ4lnZDPW6_r-q),但我得到這個錯誤「QPainter :: begin:繪製設備返回的引擎== 0,輸入:0「,我不知道爲什麼。這個想法是,我想有一個窗口可以在3dsMax,Modo中使用,也可以作爲獨立的(3dsMax和Modo都帶有PySide)。QPainter :: begin:繪製設備返回的引擎== 0,類型:0

任何想法?

下面是代碼:

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_()) 

感謝,

尼克

回答

1

我看到你的代碼錯誤的唯一的事情是,你是從QAbstractListModel繼承,但沒有實施抽象方法。

從這裏的文件:http://doc.qt.io/qt-5/qabstractlistmodel.html#details

當繼承QAbstractListModel,你必須提供實現根據rowCount()和數據的 ()函數。表現良好的模型 提供了一個headerData()實現。

遺漏任何代碼?你有沒有創建一個QPainter對象?

+0

謝謝Aaron!那對我來說太愚蠢了。這解決了它。在教程中他沒有在他的第一次運行中實現這兩種方法,所以我認爲在進一步測試之前也可以進行測試。 – Nick

+0

沒問題,如果你的問題解決了,請接受答案:) –

+0

gotcha!第一天堆棧溢出太多..我試圖在今天早上進行投票,但我沒有被允許,因爲我沒有足夠的聲望點。再次感謝:) – Nick

相關問題