我是PySide的新手,我正在尝试将此教程用于我的用例: Selectable list of Python objects in QML | Qt Wiki | Qt Project
当我传递一个回调函数并从qml MouseArea调用它时,我收到此错误:
TypeError: Result of expression 'model.on_select' [QVariant(PySide::PyObjectWrapper)] is not a function.
这是我的模型项类(或教程中称为ThingWrapper
):
class QtPasswdItem( QtCore.QObject ):
# other stuff
@QtCore.Slot()
def on_select( self ):
print 'User clicked on:'
以下是为QML设置模型的代码:
passwd_model = QtPasswdModel( [QtPasswdItem( {c: '%s%02d' % ( c, i )
for c in QtPasswdItem.COLUMNS } ) for i in xrange( 1 )] )
qtrc = qtview.rootContext()
qtrc.setContextProperty( 'passwd_model', passwd_model )
qtview.setSource( path_qml_main )
这是我的QML代码:
import QtQuick 1.0
ListView {
id: passwd_list
width: 800
height: 600
model: passwd_model
// other stuff
delegate: Component {
Rectangle {
// other stuff
MouseArea {
anchors.fill: parent
onClicked: { model.on_select() }
}
// other stuff
}
}
}