[Kde-games-devel] A QListView programming problem

Ian Wadham iandw.au at gmail.com
Tue Nov 1 21:53:15 UTC 2011


On 31/10/2011, at 10:17 AM, Albert Astals Cid wrote:
> myListView->setCurrentIndex(myListView->model()->index(myRow, 0); should do 
> the trick, sometimes it does not because in Qt4 there is a separate concept 
> for selection and current index, but as far as I remember for listviews it is 
> actually mostly the same. If it does not work send me the code you have and 
> i'll give it a try myself.

Thank you very much, Albert, for this very helpful tip.  I am sure I would never
have thought it up on my own.

It did not work at first and then I went off on a wild goose chase though the
various QModelView classes, trying this and that and shuffling the order of
execution of code.  Sometimes it worked and sometimes not.  That reminded
me of something and I tried putting the setCurrentIndex() into the code for
one of KSudoku's Main Menu actions ... then it worked every time.

It appears that QListView (like Main Window) does not complete its
initialisation during the construction of the application's main widgets.

So now there is a private slot in the WelcomeScreen gui/welcomescreen.*
to contain the setCurrentIndex() code.  The constructor invokes that slot
with a QMetaObject::invokeMethod (..., Qt::QueuedConnection, ...) and it
works fine every time.  See r1262168.

Thanks again, Albert.

All the best, Ian W.




More information about the kde-games-devel mailing list