[Kde-games-devel] A QListView programming problem
Albert Astals Cid
aacid at kde.org
Sun Oct 30 11:02:30 UTC 2011
A Diumenge, 30 d'octubre de 2011, Ian Wadham vàreu escriure:
> 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.
Not sure i understand what your problem is, can't you just save the row() of
the QModelIndex returned by QListView::selectionModel()->currentIndex() ?
Albert
>
> 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.
>
> _______________________________________________
> kde-games-devel mailing list
> kde-games-devel at kde.org
> https://mail.kde.org/mailman/listinfo/kde-games-devel
More information about the kde-games-devel
mailing list