views:

458

answers:

2

I'm making a small file-browser for my own use, in Ruby, and using Qt for the view. The idea is that it'll end up on my TV, where I can use the remote to move up and down and launch files.

Everything works fine, until I'm going to move the selection using the remote. I managed to set up a D-Bus service, so I'll just call the methods using LIRC.

The code I'm using for setting up the view looks like this:

@dm = Qt::DirModel.new
@sm = Qt::ItemSelectionModel.new(@dm)

@lv = Qt::ListView.new
@lv.model = @dm
@lv.selectionModel = @sm

cwd = @dm.index(@dir)
@lv.rootIndex = cwd

And then I'm unsure how to change the selection. Think I must have tried about every setIndex, setSelection and every method sounding similar, on the DirModel, ItemSelectionModel and ListView, without any luck. I've been googling and reading through the API without finding anything.

Ideally, I would have something like "moveSelectionDown" and "moveSelectionUp" that takes care of it, and making sure it wraps around correctly. But I can't seem to find anything.

A: 

I think you're forgetting that you have to create the ModelIndex through your model:

@dm.index(3, 0, None)

I'd try this method (Though I'm not really sure, this deselects the other cells.)

@lv.setCurrentIndex(@dm.index(3, 0, None))

I haven't used Ruby for ages, so I'm not exactly sure there's None.

Georg
A: 

Managed to fix it through the ItemSelectionModel every view apparently has.

moving up:

curIndex = @lv.currentIndex
@lv.selectionModel.setCurrentIndex(curIndex.sibling(curIndex.row-1, 0), Qt::ItemSelectionModel::ClearAndSelect)

or adding one to move down