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?
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.
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:
Code:
if (d->model)
variant = d->model->data(currentIndex(), Qt::DisplayRole);
event->accept();
}
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.