PDA

View Full Version : extended selection in q3listview



sreedhar
10th November 2006, 15:36
Hi,
i want to use similar functionality as extended selection in Q3ListView( setSelectionMode(Q3ListView::Extended) ).

And remove the functionality of
-- multiple items can be selected by dragging the mouse over them.
from the extended selection as i have drag and drop feature in my App.

please provide any code snippet if possible.

regards

jpn
10th November 2006, 16:47
Try overriding mouseMoveEvent() (or filtering the event) so that the Q3ListView implementation never receives any mouse move events..



void MyListView::mouseMoveEvent(QMouseEvent* event)
{
// override mouseMoveEvent() to make sure Q3ListView::mouseMoveEvent() is not called
event->accept();
}

// OR

Something::Something()
{
listView->installEventFilter(this);
}

bool Something::eventFilter(QObject* obj, QEvent* event)
{
// returns true and therefore filters the event
// if the list view is receiving a mouse move event
return (event->type() == QEvent::MouseMove);
}

sreedhar
10th November 2006, 17:46
hi,
I already reimplemented contentsMouseMoveEvent in my appl.

I think you misunderstood my problem. I have drag and drop in my app. for left mouse press and move , so if extended selection is used, it will select the items and the drag and drop is not working.

So is there any way to switchoff the behaviour of selection the items on mouse move for extended selection

regards

jpn
10th November 2006, 18:08
This works just fine for me:


#include <QtGui>
#include <Qt3Support>

class MyListView : public Q3ListView
{
public:
MyListView(QWidget* parent = 0) : Q3ListView(parent)
{
setSelectionMode(Q3ListView::Extended);
// just some dummy items
addColumn("");
for (int i = 0; i < 5; ++i)
new Q3ListViewItem(this, QString::number(i));
}

protected:
void contentsMouseMoveEvent(QMouseEvent* event)
{
Q_UNUSED(event);
}

};

int main(int argc, char* argv[])
{
QApplication a(argc, argv);
MyListView list;
list.show();
return a.exec();
}

sreedhar
11th November 2006, 11:28
Thanks a lot for the code.

If I use Q_UNUSED(event) in my app., it has no effect, and the mouse move on pressing the left mouse still selects the items below the mouse

I have reimplemented the drag operation in contentsMouseMoveEvent, so i cannot neglect this event.

So is there a way such that my drag along with no selection on mouse left button press and move works

regards,
sreedhar

jpn
11th November 2006, 12:44
Are you passing the event to the base class implementation? Could you show us the relevant parts of the code?

sreedhar
13th November 2006, 08:22
Yes i am passing the event to the base class implementation of q3listview

void QWaveTextView::contentsMouseMoveEvent ( QMouseEvent * me)
{
Q3ListView::contentsMouseMoveEvent(me);

if (!(me->buttons() & Qt::LeftButton))
return;

if ((me->pos() - mDragStartPos).manhattanLength()
< QApplication::startDragDistance())
return;
...
}

If i do not pass the event to the base class(q3listview), i do not get the drag to work.

I have also connected SIGNAL onItem(Q3ListViewItem *) of Q3ListView to some other slot for some other purpose, and if do not use the base class implementation, the slot connected to this signal also does not work.

regards,
sree

jpn
13th November 2006, 09:03
You don't reimplement contentsMouseMoveEvent() for that. The default implementation already calls startDrag() when appropriate. What you need to reimplement is Q3ListView::dragObject(). And remember to mark items as draggable by Q3ListViewItem::setDragEnabled().