[PySide] simple QTableView example

Frank Rueter | OHUfx frank at ohufx.com
Thu Oct 10 19:37:48 CEST 2013


After looking at some more examples I think my approach of storing 
multiple values in one item is fundamentally flawed.
Instead I should be using one item per cell and assign the respective 
data, right?!

I shall re-write the example accordingly, sorry for the noise.

frank

On 10/10/13 6:34 PM, Frank Rueter | OHUfx wrote:
> I meant QTableView not QStandardTableView :/
>
> On 10/10/13 6:33 PM, Frank Rueter | OHUfx wrote:
>> 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
>>
>>
>> _______________________________________________
>> PySide mailing list
>> PySide at qt-project.org
>> http://lists.qt-project.org/mailman/listinfo/pyside
>
>
>
> _______________________________________________
> PySide mailing list
> PySide at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/pyside

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20131010/f1c58b3b/attachment.html>


More information about the PySide mailing list