From a646bcf2be23a65c6ee0a0efdeb6e787c80ac457 Mon Sep 17 00:00:00 2001 From: Samuel Gaist Date: Thu, 20 Aug 2020 09:32:12 +0200 Subject: [PATCH] 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 --- src/widgets/itemviews/qabstractitemview.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/widgets/itemviews/qabstractitemview.cpp b/src/widgets/itemviews/qabstractitemview.cpp index a6b49c05b7..5d3fa4a088 100644 --- a/src/widgets/itemviews/qabstractitemview.cpp +++ b/src/widgets/itemviews/qabstractitemview.cpp @@ -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()) QGuiApplication::clipboard()->setText(variant.toString()); event->accept(); }