QAbstractItemView: make clipboard copy less constrained

Currently when copying from an item view, only QString value types are
considered. This severely limits the usefulness of the feature as it
does not even allow to copy number nor dates that can be translated to
text.

This merge request changes that by checking if the content being copied
can be converted to a string rather that just being a string. This will
also allow for custom types to be handled.

Fixes: QTBUG-86166
Pick-to: 5.15
Change-Id: If57c986ef5831d59eeb59f9c4b900fa126ec31ea
Reviewed-by: David Faure <david.faure@kdab.com>
This commit is contained in:
Samuel Gaist 2020-08-20 09:32:12 +02:00
parent add8262f72
commit a646bcf2be

View File

@ -2340,7 +2340,7 @@ void QAbstractItemView::keyPressEvent(QKeyEvent *event)
QVariant variant;
if (d->model)
variant = d->model->data(currentIndex(), Qt::DisplayRole);
if (variant.userType() == QMetaType::QString)
if (variant.canConvert<QString>())
QGuiApplication::clipboard()->setText(variant.toString());
event->accept();
}