Results 1 to 15 of 15

Thread: reordering QListWidgetItems of a QListWidget

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2007
    Posts
    35
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question reordering QListWidgetItems of a QListWidget

    Qt Code:
    1. void MyListWidget::dropEvent(QDropEvent* event) {
    2. QList<QListWidgetItem *> before = getListWidgets();
    3. QListWidget::dropEvent(event);
    4. //TODO remove this one
    5. //TODO do not use the qtest lib, remove it from linker
    6. //QTest::qWait(5000);
    7. QList<QListWidgetItem *> after = getListWidgets();
    8. dbg() << "before" << before;
    9. dbg() << "after" << after;
    10. //TODO: compare before and after, if not equal, emit a signal
    11. }
    12.  
    13. QList<QListWidgetItem *> MyListWidget::getListWidgets(void) {
    14. QList<QListWidgetItem *> r(findItems("*",Qt::MatchWildcard));
    15. return r;
    16. }
    To copy to clipboard, switch view to plain text mode 

    MyListWidget is a QListWidget. What I'm trying to do is emitting a signal when the widgets are really reordered, as dropEvent sometimes occurs even when the order is the same. The problem is that the list "after" contains one more element, as QListWidget::dropEvent() duplicates the QListWidgetItem before moving it to the new position (QTest::qWait() proves it).

    My question is: how, where or when to attempt to get the state of the list widgets after the copy has been removed and everything is in place, so that a simple

    Qt Code:
    1. if(after != before) emit widgetsReordered;
    To copy to clipboard, switch view to plain text mode 

    will do the job ?

  2. The following user says thank you to OriginalCopy for this useful post:

    pbek (10th August 2017)

Similar Threads

  1. Replies: 13
    Last Post: 15th December 2006, 11:52

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
  •  
Qt is a trademark of The Qt Company.