Skip to content

Commit

Permalink
QAbstractItemView: make clipboard copy less constrained
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
sgaist committed Aug 29, 2020
1 parent add8262 commit a646bcf
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/widgets/itemviews/qabstractitemview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit a646bcf

Please sign in to comment.