PDA

View Full Version : qlistview drag&drop problem



moowy
10th October 2006, 10:43
Hello, I have a problem with a qlistview. I have some custom made slides in it and I have a problem with dragging them around qlistview. I enabled the drag&drop on the qlistview like this:

//just for reference
//QListView *iconList;
iconList->setDragEnabled(true);
iconList->setViewMode(QListView::IconMode);
iconList->setIconSize(siz);
//iconList->setSelectionMode(QAbstractItemView::SingleSelectio n);
iconList->setGridSize(isiz);
iconList->setSpacing(inc_size);
iconList->setUniformItemSizes(true);
iconList->setMovement(QListView::Free);
//iconList->setMovement(QListView::Snap);
iconList->setAcceptDrops(true);
iconList->setDropIndicatorShown(true);
iconList->setResizeMode(QListView::Adjust);


If i start dragging from the top item it shows the marker but it's in the top left position. If i continue dragging (and move outside the widget area and than back -still dragging), the marker appears at the right position and stays that way until i realease the item All of the following dragging continued by the previous dragging is made completely ok (the marker is right where it should be.
Does anyone have any idea??
ps. I use this for the drag events... ( if I use qlistview events the result is absolutely awfull...)


void MListView::dropEvent(QDropEvent * event) {
//QListView::dropEvent(event);
QAbstractItemView::dropEvent(event);
}

void MListView::dragMoveEvent(QDragMoveEvent * event) {
//QListView::dragMoveEvent(event);
QAbstractItemView::dragMoveEvent(event);
}

jpn
10th October 2006, 11:07
Hmm, sounds like you are mixing two things up; 1) moving items around the list view and 2) drag'n'drop. You don't need drag'n' drop for moving items around the list view:



#include <QtGui>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);

QListView list;
list.setViewMode(QListView::IconMode);
list.setGridSize(QSize(20,20));
list.setMovement(QListView::Snap);

QStringListModel model(QStringList() << "a" << "b" << "c");
list.setModel(&model);
list.show();

return a.exec();
}

moowy
10th October 2006, 11:35
I'm not sure what did u try to achieve with you're test program (i compiled it and the movement doesn't work), but u we're right. I did confuse drag&drop and movement. But I still need both (to move files between different tabs). The problem is still the same (untill I move one element outside the widget I get the movement marker at the wrong place).

jpn
10th October 2006, 11:45
Heh, it indeed doesn't seem to work with 4.1.4 whereas the movement works fine in 4.2.0. :)
But there you see how important it is to describe the actual problem.. So the problem was not moving items within a list view, the problem was with drag'n'dropping items between two different list views, right?

moowy
10th October 2006, 11:51
I'll try to upgrade ... :) You're right, it is vital to address the problem properly. But the problem is the same. The problem is with the actual movement within the same listview and not with the drag&drop. Do you have any ideas how to fix this?

moowy
10th October 2006, 12:24
Do you think that I have something wrong with my flags.. ?



Qt::ItemFlags MyClass::flags(const QModelIndex &index) const
{
if (index.isValid())
return Qt::ItemIsEnabled | Qt::ItemIsSelectable
| Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;

return Qt::ItemIsEnabled | Qt::ItemIsDropEnabled;/*| Qt::ItemIsSelectable;*/
}


or with the way I initialize qlistviews gridsize:


QSize siz = whiteboard->size;
QSize isiz = siz + QSize(3*inc_size, 3*inc_size);

iconList->setIconSize(siz);
iconList->setGridSize(isiz);
iconList->setSpacing(inc_size);
iconList->setUniformItemSizes(true);
iconList->setMovement(QListView::Snap);

moowy
11th October 2006, 15:45
Ok. I have 1t 4.2.0 up and running. My question still remains: is there any way to draw some kind of marker where the item is being moved while in movement (beside the plus) ??

moowy
12th October 2006, 15:24
Qt 4.2.0 is absolutely terrible. It isn't ready for the release yet. So my question is next: is there any way to draw something to indicate where the item is being moved inside a qlistview ( like a line or a box maybe ) ??

moowy
13th October 2006, 14:49
Ok. This thread is turning into a monologe. If anyone can help me I have my latest conclusion on the qlistview movement problem.... Ok I found out that the moving marker is shown for every slide as long as it is inside parent widgets viewport area.
Example:

i have 200*400 wide area and the area is abstractscrollarea so it can be bigger than the 200*400 and i just scroll to the right slide. here's the trick, if i move outside 200*400 area (scroll down) the moving marker stops showing and i have nothing showing for the movement.

Does anyone have any idea??