Results 1 to 3 of 3

Thread: QListView/QListWidget: copy multiple items and paste elsewhere

  1. #1
    Join Date
    Jun 2010
    Posts
    8
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QListView/QListWidget: copy multiple items and paste elsewhere

    I have a QListWidget with its selectionMode set to QAbstractView.ExtendedSelection. So I can select multiple items (rows) in the QListWidget.

    If I select multiple items, press Copy (Ctrl+C), and then paste the result elsewhere, either in a Qt text widget or in some non-Qt place, I get the text of only the last item. How can I get the selection to include the text of all the selected items, separated by newlines or something like that?

  2. #2
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QListView/QListWidget: copy multiple items and paste elsewhere

    Based on gut feeling I'd say that the QListWidget only produces the mime-data for the currently selected item. I could be wrong there. However, you can overload the mimeData() function and adapt it to your needs.

  3. #3
    Join Date
    Jun 2010
    Posts
    8
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QListView/QListWidget: copy multiple items and paste elsewhere

    It wasn't mimeData(), but franz set me a track of where to look. QAbstractItemView::keyPressEvent() handles Ctrl+C:
    Qt Code:
    1. if (event == QKeySequence::Copy) {
    2. QVariant variant;
    3. if (d->model)
    4. variant = d->model->data(currentIndex(), Qt::DisplayRole);
    5. if (variant.type() == QVariant::String)
    6. QApplication::clipboard()->setText(variant.toString());
    7. event->accept();
    8. }
    To copy to clipboard, switch view to plain text mode 
    You can see that it gets some string data from currentIndex(), which is a single item: it's not going to handle multiple selected items. So I have to subclass QListWidget and reimplement keyPressEvent() to make this work the way I want.

Similar Threads

  1. add custom widget items to QListView or QListWidget
    By yazwas in forum Qt Programming
    Replies: 2
    Last Post: 16th September 2010, 23:36
  2. copy and paste
    By hubipet in forum Qt Tools
    Replies: 1
    Last Post: 17th July 2009, 07:19
  3. Multiple Lines per item in a QListWidget/QListView
    By youkai in forum Qt Programming
    Replies: 1
    Last Post: 27th August 2008, 22:44
  4. using cut(), copy(), paste()
    By systemz89 in forum Newbie
    Replies: 5
    Last Post: 18th December 2007, 15:47
  5. Replies: 8
    Last Post: 10th November 2006, 10:39

Tags for this Thread

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.