[Kde-games-devel] A QListView programming problem

Ian Wadham iandw.au at gmail.com
Sun Oct 30 05:22:59 UTC 2011


Hi guys,

In KSudoku the WelcomeScreen contains a list of puzzle types and
sizes from which the user can select.  I would like to be able to save
and restore this selection between sessions, using KConfigGroup.

I thought I could just save and restore an integer row-index, but no
such luck.  The list is displayed in a QListView, which is declared in
code generated from a *.ui file created by Designer.  In QListView the
list is accessed by using QListView::selectionModel()->currentIndex()
to obtain a QModelIndex object and then that index-object is used to
retrieve a row from the underlying data collection.  IOW there seems
to be no easy way to find out where the cursor and highlighting are.

I do not think you can save an index-object in KConfigGroup.  I googled
about on this, but it seems that there is no easy answer for finding
where the cursor and selection highlighting is in a QListView and then
resetting that position on a later occasion.

The best way seems to be to remember one or two attributes of the data
and, when restoring, search the entire QListView data, find the item you
want (e.g. by its attribute values) and set the selection there.

Does anybody know a better way?

All the best, Ian W.

P.S. KSudoku's list is always displayed in the same order.



More information about the kde-games-devel mailing list