[Qt-interest] Moving through a QListView using D-Bus
Per Christian B. Viken
perchr at northblue.org
Thu Feb 26 20:43:21 CET 2009
On Feb 26, 2009, at 7:27 PM, Andre Somers wrote:
> Per Christian B. Viken wrote:
>> Hi.
>> I'm currently using Qt4 with Ruby to see if I can build a small
>> media launcher I can use via my remote. It basically displays a
>> giant QListView on the entire screen, using a QDirModel to get
>> files and folders. I figured that the easiest way to make LIRC and
>> the application talk was using D-Bus, but if another solution works
>> better, I'm open to suggestions.
>> The problem is that I can't figure out a way to move the current
>> selection up and down without using the mouse or keyboard.
>> So far I've tried faking a keypress, emitting a keyReleaseEvent
>> with the correct event (Down released), but this doesn't seem to
>> work.
>> Also tried:
>> curIndex = listView.currentIndex
>> listView.setCurrentIndex(curIndex.child(curIndex.row+1, 0))
>> which is executed, but only seems to deselect that which was
>> selected with the mouse already. When nothing is selected, nothing
>> happens.
>> (I'm not very familiar with Qt at the moment, but I have searched
>> through the API without finding much that works. Figured I should
>> try with Ruby first, since I already know that, and avoid fighting
>> with C++ and Qt at the same time. Then learn C++ later on.)
>
> Every view has a selectionModel. I think it will help you along.
> Also, I think your calculation of the index is wrong. You don't
> want the child, you want the next sibling of the current item.
>
> Regards,
>
> André
>
> (P.S. emailing privately because I have some issues posting to the
> list with Thunderbird. Sorry.)
Thanks, that did the trick!
I looked at the selectionModel as well, but since that gave the same
results, I kind of forgot about it. But using sibling instead of child
works like a charm.
Only issue now is that it doesn't like it when I move too far up, or
too far down, but a few tests should take care of that. And I think I
can manage on my own.
More information about the Qt-interest-old
mailing list