[PyQt] Trouble implementing a TableView model

Mark Summerfield list at qtrac.plus.com
Tue Aug 3 14:26:38 BST 2010


Hi Bernard,

On Tue, 3 Aug 2010 08:09:25 -0400
"Bernard Van Der Stichele" <Bernard_VanDerStichele at otpp.com> wrote:

> A while back, I had asked the group how I could implement a numeical
> sort on a TableWidget.
> Someone kindly showed me how to implement a model, associated with a 
> TableView. The sample code was posted here: 
> http://diotavelli.net/PyQtWiki/Sorting%20numbers%20in%20columns
>  
> I'm having problems implementing this in my app. In this simple
> example, I use Qt Designer to create a MainForm containing a
> TableView (gridView), a LineEdit (queryBox) and a PushButton
> (runQueryBtn). The designer files (.ui and ui_xxx.py) generated
> defines the TableView in a couple of lines - I have not used the
> Designer to change any of the default object properties.
>  
> The problem I have is that the TableView remains blank. I do not 
> understand what I'm missing, as I tried to follow the same workflow
> as provided by the code linked-to above..
> The code works, in that the data I want to display is retrieved from
> a database and I receive no runtime warnings or errors.
>  
> Any help is greatly appreciated... this is probably one of those
> simple newbie errors.
>  
> My application shell is as follows:
[snip]

I've only had the chance for a quick glimpse at your code.

One thought would be to replace

    model

with

    self.model

because I think it might be getting garbage collected. (Or give the
model a parent.)

BTW You might be able to avoid a proxy altogether since you're using
standard items: look up QStandardItemModel.sortRole() &
QStandardItemModel.setSortRole().

[snip]



-- 
Mark Summerfield, Qtrac Ltd, www.qtrac.eu
    C++, Python, Qt, PyQt - training and consultancy
        "Advanced Qt Programming" - ISBN 0321635906
            http://www.qtrac.eu/aqpbook.html


More information about the PyQt mailing list