Results 1 to 6 of 6

Thread: QListWidget help please

  1. #1
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default QListWidget help please

    Hi All,

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

    Qt Code:
    1. setSelectionMode(QAbstractItemView::ExtendedSelection);
    2. setAcceptDrops(true);
    3. setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    To copy to clipboard, switch view to plain text mode 

    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.
    Attached Images Attached Images

  2. #2
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QListWidget help please

    Any ideas on this one?

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QListWidget help please

    Could you provide a minimal compilable example which reproduces the problem?

  4. #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: QListWidget help please

    Did you, by any chance, forget to call QAbstractItemView::setDragEnabled(true)?

    Qt Code:
    1. #include <QtGui>
    2.  
    3. static void initList(QListWidget* list)
    4. {
    5. list->setDragEnabled(true);
    6. list->setAcceptDrops(true);
    7. list->setDropIndicatorShown(true);
    8. for (int i = 0; i < 10; ++i)
    9. list->addItem(QString::number(i));
    10. list->setSelectionMode(QAbstractItemView::ExtendedSelection);
    11. }
    12.  
    13. int main(int argc, char *argv[])
    14. {
    15. QApplication a(argc, argv);
    16. QListWidget list1;
    17. QListWidget list2;
    18. initList(&list1);
    19. initList(&list2);
    20. list1.show();
    21. list2.show();
    22. return a.exec();
    23. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  5. #5
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QListWidget help please

    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.

  6. #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: QListWidget help please

    Quote Originally Posted by munna View Post
    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.
    J-P Nurmi

Similar Threads

  1. Get Visible Items from the QListWidget
    By srj in forum Qt Programming
    Replies: 4
    Last Post: 22nd November 2006, 20:13
  2. Qt 4.2: QListWidget changes size of its items
    By KingFish in forum Qt Programming
    Replies: 2
    Last Post: 25th October 2006, 11:06
  3. QTreeWidget & QListWidget different selection
    By munna in forum Qt Programming
    Replies: 9
    Last Post: 21st July 2006, 06:50
  4. keypress while editing an item in QListWidget
    By Beluvius in forum Qt Programming
    Replies: 3
    Last Post: 4th April 2006, 09:56
  5. QListWidget add QListWidgetItem
    By fellobo in forum Qt Programming
    Replies: 3
    Last Post: 20th February 2006, 19:37

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.