![]() |
QListWidget::currentItemChanged problem
Hey,
I'm having some trouble with the selecting behaviour of my QListWidget.. What I'd like it to achieve is to change the currentItem ONLY when an item is pressed, not when scrolling. But it also changes the currentItem when scrolling, because I'm touching a different entry in the list. The currentItemChanged slot has 2 arguments, "QListWidgetItem * current" and "QListWidgetItem * previous". Let's say I've got item A and B. Item A was selected by pressing, and it changed to B because of scrolling. The problem is this: I decided to change the currently selected item (B) to the previously selected item (A), so that it wouldn't change when scrolling. But then the slot is called again, because it changed. And of course, then B is the previous, ands it changes to B again. This is an infinite loop. Of course I've tried a fair amount of things with if-statements and stuff, and searched with Google, but no luck unfortunately. Does anyone know a way to bypass this slot function? :D Any help is much appreciated ;) |
Re: QListWidget::currentItemChanged problem
It might be difficult to implement if you want do something when item is pressed, because it will also get pressed when scrolling. Use QListWidget::itemClicked(QListWidgetItem *item) signal instead.
|
Re: QListWidget::currentItemChanged problem
Thanks :) but I have a slot like that already, one for itemClicked and one for itemChanged.
I did notice something, even though an other item is set as current when scrolling, the clicked item is still selected(blue), I might make something like "Set currently selected as current item". The thing is that currentItem, currentRow and currentIndex are changed when scrolling. I'll have a look at it again when I'm home, took me about 3 hours without success yesterday :D |
Re: QListWidget::currentItemChanged problem
I'm not sure what you are trying to do but can you use QListWidget::itemSelectionChanged signal and check which item is selected?
|
Re: QListWidget::currentItemChanged problem
Quote:
|
Re: QListWidget::currentItemChanged problem
Diph, that worked :D
In the connected slot function I've put: Code:
if(ui->fileList->currentItem()->isSelected() == false) The problem was that when scrolling, the current item changed, but that item wasn't selected. It's not really user friendly when item A is selected (blue), while B is the current item while/after scrolling. Unbelievable how simple the solution is, considering all the complex concepts I've let loose on this issue. Thanks! |
All times are GMT. The time now is 10:29. |
vBulletin® Version 3.8.8