On Thu, Aug 25, 2011 at 11:44 AM, Tim Doty <[email protected]> wrote: > On Aug 22, 2011, at 4:57 PM, Ben Breslauer wrote: > > > Hi, > > > > I think these are bugs but I'm not sure, so, in case I'm doing something > wrong, I'm emailing first. I am using Python 2.7.2, PySide 1.0.5, Qt 4.7.3, > and ArchLinux with kernel 3.0.3. > > > > I'm porting an application from PyQt4, and the code works as intended > there. I'm trying to create a table by subclassing QAbstractTableModel and > using QTableView. When I minimally implement QAbstractTableModel (just > implementing rowCount, columnCount, data, headerData, and flags) the > resulting table is not how I would expect it to look (again, based on my > experiences with PyQt4). > > > > First, each cell has a checkbox in it, even though I have not requested > that the cells be checkable, nor is the data boolean values. I cannot find > any setCheckable-like method to use with the model or view, and flags() > never includes Qt.ItemIsUserCheckable. > > I've run into the same issue. You may not realize it, but each cell also > has a blank icon. I've gone chasing through the documentation and gotten > nowhere. > > You have re-implemented data() -- you will find that returning None for > roles 1 and 10 (icon and check state, respectively) eliminate the display of > the checkbox and the empty space for the non-existent icon. > > Thanks! That works perfectly! I think this also solved my second problem, which probably had to do with data() returning unexpected values in some cases.
> If that is indeed the case it would be nice for it to be documented. The > PySide docs say you must implement rowCount(), columnCount() and data() -- > but it doesn't give any hint as to what the implementation of data() might > need to handle. Just a brief statement that an implementation of data() must > account for each of the roles (with a link to the page enumerating them) > would be helpful for those unfamiliar with Qt. > Upon a closer inspection of the documentation, I noticed that QAbstractItemModel does indeed mention that if you do not have a value to return, you should return an invalid QVariant. I had been doing that when I was using PyQt, but upon the switch to PySide I did not realize that invalid QVariants should be changed to None (I must have missed that when reading the PSEP). I do agree that the docs could be more helpful in explaining how to subclass a model, though. I think it would probably be better for that to be done in the Qt docs instead of the PySide docs, since it applies to Qt generally. Ben
_______________________________________________ PySide mailing list [email protected] http://lists.pyside.org/listinfo/pyside
