[PySide] simple QTableView example

Frank Rueter | OHUfx frank at ohufx.com
Thu Oct 10 18:33:05 CEST 2013


Hi all,

after a bit of a break from PySide I am trying to wrap my head around 
the model/view stuff again and am trying to understand how a very simple 
example would work where a QStandarItem has properties "title", 
"priority" and "finished" which are displayed via a QStandardTableView.

I am struggling with understanding how to properly display the above 
three properties in the table's columns. I tried setting the data() 
method on the model like this:

/    def data(self, index, role=QtCore.Qt.DisplayRole)://
//        '''Return data based on index and role'''//
//        item = self.itemFromIndex(index)//
//        if index.column() == 0://
//            return item.title//
//        elif index.column() == 1://
//            return item.finished//
//        elif index.column() == 2://
//            return item.priority/

but for some reason it errors saying item does not have attribute 
"finished" even though my item object s declared like this:

/class TaskItem(QtGui.QStandardItem)://
//    '''Item to hold a task for the todo list'''//
////
//    def __init__(self, title, finished=False, priority=1)://
//        super(TaskItem, self).__init__(title)//
//        self.title = title//
//        self.finished = finished//
//        self.priority = priority/


When printing the item's attributes via dir() I see that, when the model 
is populated, the last item it attempts to call is not my custom item 
object, but something else with less attributes and methods. Clearly 
there is something I haven't quite understood about this process.

Also, if I use the models data() method as pointed out above, I get 
checkboxes in the cells which I don't want at this stage.

Can somebody please help me understand where I go wrong?
Attached is the whole test code.

Cheers,
frank

P.S.: I am aware that the controller code shouldn't necessarily live in 
the QWidget's methods, this is just for testing which I will clean up 
once I get how it all connects again
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20131010/5ce94e77/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ToDoPanel.py
Type: text/x-python-script
Size: 2706 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20131010/5ce94e77/attachment.bin>


More information about the PySide mailing list