Reply
Thread Tools
Berserk's Avatar
Posts: 199 | Thanked: 156 times | Joined on May 2010 @ Holland
#1
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?
Any help is much appreciated
__________________
Wallpaeper - Desktop background manager (in Extras!)
Config Reader - Export all Gconf to an HTML file + compare feature (Extras-testing)
Even though these programs are available for free, I would appreciate any donations
 
Posts: 180 | Thanked: 76 times | Joined on May 2010
#2
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.
 

The Following User Says Thank You to Diph For This Useful Post:
Berserk's Avatar
Posts: 199 | Thanked: 156 times | Joined on May 2010 @ Holland
#3
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
__________________
Wallpaeper - Desktop background manager (in Extras!)
Config Reader - Export all Gconf to an HTML file + compare feature (Extras-testing)
Even though these programs are available for free, I would appreciate any donations
 
Posts: 180 | Thanked: 76 times | Joined on May 2010
#4
I'm not sure what you are trying to do but can you use QListWidget::itemSelectionChanged signal and check which item is selected?
 

The Following 2 Users Say Thank You to Diph For This Useful Post:
Berserk's Avatar
Posts: 199 | Thanked: 156 times | Joined on May 2010 @ Holland
#5
Originally Posted by Diph View Post
I'm not sure what you are trying to do but can you use QListWidget::itemSelectionChanged signal and check which item is selected?
Thanks, I'll try this when I'm home!
__________________
Wallpaeper - Desktop background manager (in Extras!)
Config Reader - Export all Gconf to an HTML file + compare feature (Extras-testing)
Even though these programs are available for free, I would appreciate any donations
 
Berserk's Avatar
Posts: 199 | Thanked: 156 times | Joined on May 2010 @ Holland
#6
Diph, that worked

In the connected slot function I've put:
Code:
if(ui->fileList->currentItem()->isSelected() == false)
        ui->fileList->currentItem()->setSelected(true);
To make sure it really selects the currently selected item.

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!
__________________
Wallpaeper - Desktop background manager (in Extras!)
Config Reader - Export all Gconf to an HTML file + compare feature (Extras-testing)
Even though these programs are available for free, I would appreciate any donations
 
Reply


 
Forum Jump


All times are GMT. The time now is 12:15.