Results 1 to 8 of 8

Thread: extended selection in q3listview

  1. #1
    Join Date
    Feb 2006
    Posts
    60
    Thanks
    21
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default extended selection in q3listview

    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

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: extended selection in q3listview

    Try overriding mouseMoveEvent() (or filtering the event) so that the Q3ListView implementation never receives any mouse move events..

    Qt Code:
    1. void MyListView::mouseMoveEvent(QMouseEvent* event)
    2. {
    3. // override mouseMoveEvent() to make sure Q3ListView::mouseMoveEvent() is not called
    4. event->accept();
    5. }
    6.  
    7. // OR
    8.  
    9. Something::Something()
    10. {
    11. listView->installEventFilter(this);
    12. }
    13.  
    14. bool Something::eventFilter(QObject* obj, QEvent* event)
    15. {
    16. // returns true and therefore filters the event
    17. // if the list view is receiving a mouse move event
    18. return (event->type() == QEvent::MouseMove);
    19. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  3. The following user says thank you to jpn for this useful post:

    sreedhar (10th November 2006)

  4. #3
    Join Date
    Feb 2006
    Posts
    60
    Thanks
    21
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: extended selection in q3listview

    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

  5. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: extended selection in q3listview

    This works just fine for me:
    Qt Code:
    1. #include <QtGui>
    2. #include <Qt3Support>
    3.  
    4. class MyListView : public Q3ListView
    5. {
    6. public:
    7. MyListView(QWidget* parent = 0) : Q3ListView(parent)
    8. {
    9. setSelectionMode(Q3ListView::Extended);
    10. // just some dummy items
    11. addColumn("");
    12. for (int i = 0; i < 5; ++i)
    13. new Q3ListViewItem(this, QString::number(i));
    14. }
    15.  
    16. protected:
    17. void contentsMouseMoveEvent(QMouseEvent* event)
    18. {
    19. Q_UNUSED(event);
    20. }
    21.  
    22. };
    23.  
    24. int main(int argc, char* argv[])
    25. {
    26. QApplication a(argc, argv);
    27. MyListView list;
    28. list.show();
    29. return a.exec();
    30. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  6. The following user says thank you to jpn for this useful post:

    sreedhar (11th November 2006)

  7. #5
    Join Date
    Feb 2006
    Posts
    60
    Thanks
    21
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: extended selection in q3listview

    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

  8. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: extended selection in q3listview

    Are you passing the event to the base class implementation? Could you show us the relevant parts of the code?
    J-P Nurmi

  9. #7
    Join Date
    Feb 2006
    Posts
    60
    Thanks
    21
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: extended selection in q3listview

    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

  10. #8
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: extended selection in q3listview

    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().
    J-P Nurmi

Similar Threads

  1. [SOLVED] QTreeView drawing selection with icons
    By Timewarp in forum Qt Programming
    Replies: 7
    Last Post: 7th February 2013, 07:52
  2. CheckBox and selection in QTableView
    By Mike Krus in forum Qt Programming
    Replies: 1
    Last Post: 21st September 2006, 20:31
  3. QTreeWidget & QListWidget different selection
    By munna in forum Qt Programming
    Replies: 9
    Last Post: 21st July 2006, 06:50
  4. QListWidget selection behavior
    By Arthur in forum Qt Programming
    Replies: 1
    Last Post: 30th May 2006, 14:10
  5. QSortFilterProxyModel signal and selection confusion
    By pascal123 in forum Qt Programming
    Replies: 1
    Last Post: 1st April 2006, 16:25

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.