summaryrefslogtreecommitdiffstats
path: root/examples/widgets
diff options
context:
space:
mode:
authorShawn Rutledge <[email protected]>2025-03-13 16:53:50 +0100
committerShawn Rutledge <[email protected]>2025-03-17 21:14:01 +0100
commit1750acc3921148b0ffc8f9f1421b87a2f5522a2e (patch)
tree66fb985cdf681924b6dae9d6574a86c20c859f14 /examples/widgets
parent70b8dd2b7eb1a874ff0ac8b4e42b03d639321394 (diff)
DropSite example: handle application/x-color
Show the color that is dragged in, both graphically and textually. Revert to default palette for other data types. Prioritize colors over text: if an application (such as kolourpaint) offers both x-color and text, the color is probably the intention, and the text may be just a hex string for placing into a color text field. Pick-to: 6.8 6.9 Fixes: QTBUG-134313 Change-Id: I6c19f1220712881d2057bc9758bbc8cbd9247c81 Reviewed-by: Liang Qi <[email protected]>
Diffstat (limited to 'examples/widgets')
-rw-r--r--examples/widgets/draganddrop/dropsite/droparea.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/examples/widgets/draganddrop/dropsite/droparea.cpp b/examples/widgets/draganddrop/dropsite/droparea.cpp
index 1b2ff1820d0..0dda206e9e7 100644
--- a/examples/widgets/draganddrop/dropsite/droparea.cpp
+++ b/examples/widgets/draganddrop/dropsite/droparea.cpp
@@ -48,6 +48,11 @@ void DropArea::dropEvent(QDropEvent *event)
//! [dropEvent() function part2]
if (mimeData->hasImage()) {
setPixmap(qvariant_cast<QPixmap>(mimeData->imageData()));
+ } else if (mimeData->hasColor()) {
+ const auto color = mimeData->colorData().value<QColor>();
+ setText(tr("Color: %1").arg(color.name()));
+ setPalette(QPalette(color));
+ setBackgroundRole(QPalette::Button);
} else if (mimeData->hasFormat(u"text/markdown"_s)) {
setText(QString::fromUtf8(mimeData->data(u"text/markdown"_s)));
setTextFormat(Qt::MarkdownText);
@@ -69,7 +74,10 @@ void DropArea::dropEvent(QDropEvent *event)
//! [dropEvent() function part2]
//! [dropEvent() function part3]
- setBackgroundRole(QPalette::Dark);
+ if (!mimeData->hasColor()) {
+ setPalette({});
+ setBackgroundRole(QPalette::Dark);
+ }
event->acceptProposedAction();
}
//! [dropEvent() function part3]