PDA

View Full Version : QListWidget help please



munna
27th November 2006, 10:30
Hi All,

In my application I have a reimplemented QListWidget and constructor looks something like this




setSelectionMode(QAbstractItemView::ExtendedSelect ion);
setAcceptDrops(true);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOf f);



In this widget user can selected multiple items and then drag them into another widget which reads info of all the items that are being dropped. QListWidget is behaving strange.

Let us assume that there are 20 items in the widget. Let us call them Item1, Item2....Item20.

Here are the steps that are performed.

STEP 1: User Selects multiple items using mouse (Press, drag to select and then Release). Around 10 items are selected. Lets say Item1 to Item10 are selected. (Image1)

STEP 2: User presses (not click) the mouse on the Item10 in order to drag all the selected items. Only Item10 is selected and only Item10 can be dragged. This is not the desired behavior, therefore user releases the mouse button. (Image2)

STEP 3: Now, user presses the mouse on Item1. This time all the items that were selected in STEP1 (item1 to item 10) are selected. Dragging items happens as accepted and the items are dropped at the drop site perfectly. (Image3)

Any ideas on why is this happening ?

Thanks a lot.

munna
28th November 2006, 06:51
Any ideas on this one?

wysota
28th November 2006, 07:00
Could you provide a minimal compilable example which reproduces the problem?

jpn
28th November 2006, 09:01
Did you, by any chance, forget to call QAbstractItemView::setDragEnabled(true)?



#include <QtGui>

static void initList(QListWidget* list)
{
list->setDragEnabled(true);
list->setAcceptDrops(true);
list->setDropIndicatorShown(true);
for (int i = 0; i < 10; ++i)
list->addItem(QString::number(i));
list->setSelectionMode(QAbstractItemView::ExtendedSelect ion);
}

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QListWidget list1;
QListWidget list2;
initList(&list1);
initList(&list2);
list1.show();
list2.show();
return a.exec();
}

munna
28th November 2006, 11:51
If I set dragEnabled to true then user cannot select multiple items by just dragging the mouse.

I think it will be good if i can provide a minimum compilable example.

Give me some time. I'll post the code here.

jpn
28th November 2006, 12:16
If I set dragEnabled to true then user cannot select multiple items by just dragging the mouse.
I think that's fairly reasonable. There must be a distinction between dragging items and selecting items by dragging. You can't have both because it would be kind of impossible to know when the user wants to (de)select and when to drag.

I think it's still possible to change the behaviour by overriding appropriate mouse event handlers and adjusting for example the dragEnabled property on the fly according to the selection state of pressed index.