First of all, thanks to all the PySide devs for your efforts in delivering
this great set of python - qt bindings!
While adapting my application to the new 0.4.1 (Maemo Fremantle) release, I
hit a possible bug (I mean, everything used to work just fine with PySide
0.3.x); I attached a sample code to this message which triggers this error:
Error calling slot "openSubWin"
Traceback (most recent call last):
File "pyside-example.py", line 21, in openSubWin
self.subWindow.show()
NotImplementedError: pure virtual method 'QAbstractListModel.rowCount()' not
implemented.
Traceback (most recent call last):
File "pyside-example.py", line 65, in <module>
sys.exit(app.exec_())
NotImplementedError: pure virtual method 'QAbstractListModel.rowCount()' not
implemented.
The offending line is number 53 in function "data":
def data(self,index = QModelIndex(),role = Qt.DisplayRole):
----> if index.isValid() & (index.row() >= 0) & (index.row() <
index.model().rowCount()): <----
if role == Qt.DisplayRole:
return self.__items[index.row()]
else:
return None
else:
return None
accessing the data model using index.model() seems to cause the vanishing of
the (re)definition of the "rowCount" method; if we change the line in:
if index.isValid() & (index.row() >= 0) & (index.row() <
self.rowCount()):
it works as expected, but sometimes this is not possible (inside a custom
item delegate class, for example, its methods receive a QModelIndex instance
as a parameter, and I need its model() property to properly work).
--
Luca Donaggio
from PySide.QtCore import *
from PySide.QtGui import *
from PySide.QtMaemo5 import *
import sys
class MyWindow(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
self.setAttribute(Qt.WA_Maemo5StackedWindow)
self.cw = QWidget(self)
self.button = QPushButton(self)
self.button.setText(u'Push me')
self.vbox = QVBoxLayout(self.cw)
self.vbox.addWidget(self.button)
self.vbox.setSizeConstraint(QLayout.SetMinAndMaxSize)
self.setCentralWidget(self.cw)
self.button.clicked.connect(self.openSubWin)
def openSubWin(self):
self.subWindow = SubWindow(self)
self.subWindow.show()
class SubWindow(QMainWindow):
def __init__(self, parent):
QMainWindow.__init__(self, parent)
self.setAttribute(Qt.WA_Maemo5StackedWindow)
self.listmodel = ExampleListModel()
self.list = QListView(self)
self.list.setModel(self.listmodel)
self.setCentralWidget(self.list)
'''
Example list data model
'''
class ExampleListModel(QAbstractListModel):
'''
Class constructor
'''
def __init__(self):
QAbstractListModel.__init__(self)
self.__items = ['First','Second','Third','Fourth','Fifth','Sixth']
'''
Return the number of items in the model
'''
def rowCount(self,parent = QModelIndex()):
return len(self.__items)
'''
Return informations about the items in the model
'''
def data(self,index = QModelIndex(),role = Qt.DisplayRole):
if index.isValid() & (index.row() >= 0) & (index.row() < index.model().rowCount()):
if role == Qt.DisplayRole:
return self.__items[index.row()]
else:
return None
else:
return None
if __name__ == '__main__':
app = QApplication(sys.argv)
sw = MyWindow()
sw.show()
sys.exit(app.exec_())
_______________________________________________
PySide mailing list
[email protected]
http://lists.openbossa.org/listinfo/pyside