[PyKDE] more on the QTableView

Andreas Pakulat apaku at gmx.de
Sun Aug 27 19:10:34 BST 2006


On 27.08.06 13:32:34, basse wrote:
> anyway, I decided to try .. basic functionality I was able to add with 
> QStandardItemModel() as model, but it's not quite enough. 
> what about sorting? model seems to have sort() function, but nothing happens 
> when I use that.

You don't need to.

> also, I couldn't find sortingEnabled() function anywhere, so 
> that my table could be sorted by clicking header.. ?

With a QTableView you need to disconnect the horizontalHeader's
signal "sectionPressed" from the selectColumn slot of the view and
reconnect the signal to sortByColumn. In C++ this looks like this:

  disconnect(horizontalHeader(), SIGNAL(sectionPressed(int)), this, SLOT(selectColumn(int)));
  connect(horizontalHeader(), SIGNAL(sectionPressed(int)), this, SLOT(sortByColumn(int)));
  horizontalHeader()->setSortIndicatorShown(true);

> i looked into QProxyModel() as model, but it just got more and more complex.. 
> looks like QProxyModel() can have another model assigned with setModel but.. 
> uh, I just don't have enough experience on these views and models..
> documentation seems to be mostly C api like, and I don't read C that well.. 

You better take QSortFilterProxyModel, together with the above you do
something like:

create your model
create proxy
set source model of proxy
create view
set view's model to proxy
enable sorting as above.

> anyone willing to help me out?
> or point me to a nice example, or a doc.. ?

PyQt4 comes with a whole bunch of examples for the itemview's. And also
the Qt4 documentation has a separate section on the views, explaining
all the concepts and how everything works together.

Andreas

-- 
Your present plans will be successful.




More information about the PyQt mailing list