QListWidget::currentItem() issue
Hi,
I connected the QListWidget::itemSelectionChanged() signal to a slot.
In the slot I extract the selected item string - and append it to another string.
The problem is, that the currentItem() always returns the previous selected item - when I select using the mouse (even if I select one item after the other in the list - so the focus always stays on the list).
However, if I change the selection with the keybaord (with the arrows) currentItem() returns the correct item (since I know that per definition, currentItem() is the item with keyboard focus.
But shouldn't the mouse selection also count in this case? (could this be a bug?)
And what can I do in order to have the correct current item when selecting with the mouse?
The reason I am using the itemSelectionChanged() signal, is that it is the only one that is emitted with out a parameter when a QListWidget is clicked.
And I don't want one with a parameter, since this slot reacts to several list selections, and works on several currentItem()'s.
Thanks in advance.
Re: QListWidget::currentItem() issue
Quote:
Originally Posted by
high_flyer
But shouldn't the mouse selection also count in this case? (could this be a bug?)
And what can I do in order to have the correct current item when selecting with the mouse?
Yeah, it seems a bit weird. I can reproduce the issue. But if you're specially interested about the current item, how about using something like
?
Re: QListWidget::currentItem() issue
Thank you both.
Jpn - I am aware I can do that - but I was curious if there is a "correct" way to do this that I might not be aware of (since I am not that experienced with data aware widgets in Qt4 - yet).
What you suggested just seems "dirty", but I will probably use it since I have no choice.
Do you guys think this counts as a bug? should I report it?
davit: I have just a simple lists, with single selction, in which I need to know which item is currently selected.
So for that your code is an overkill - thanks never the less!
Re: QListWidget::currentItem() issue
Quote:
Originally Posted by
high_flyer
Jpn - I am aware I can do that - but I was curious if there is a "correct" way to do this that I might not be aware of (since I am not that experienced with data aware widgets in Qt4 - yet).
What you suggested just seems "dirty", but I will probably use it since I have no choice.
The point is that still if selected items and the current item have a relation of some kind, one should not monitor the selection in case he is interested about the current item. And vice versa. They are related, but different concepts. ;)