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 <liang.qi@qt.io>
This commit is contained in:
parent
70b8dd2b7e
commit
1750acc392
@ -48,6 +48,11 @@ void DropArea::dropEvent(QDropEvent *event)
|
|||||||
//! [dropEvent() function part2]
|
//! [dropEvent() function part2]
|
||||||
if (mimeData->hasImage()) {
|
if (mimeData->hasImage()) {
|
||||||
setPixmap(qvariant_cast<QPixmap>(mimeData->imageData()));
|
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)) {
|
} else if (mimeData->hasFormat(u"text/markdown"_s)) {
|
||||||
setText(QString::fromUtf8(mimeData->data(u"text/markdown"_s)));
|
setText(QString::fromUtf8(mimeData->data(u"text/markdown"_s)));
|
||||||
setTextFormat(Qt::MarkdownText);
|
setTextFormat(Qt::MarkdownText);
|
||||||
@ -69,7 +74,10 @@ void DropArea::dropEvent(QDropEvent *event)
|
|||||||
//! [dropEvent() function part2]
|
//! [dropEvent() function part2]
|
||||||
|
|
||||||
//! [dropEvent() function part3]
|
//! [dropEvent() function part3]
|
||||||
setBackgroundRole(QPalette::Dark);
|
if (!mimeData->hasColor()) {
|
||||||
|
setPalette({});
|
||||||
|
setBackgroundRole(QPalette::Dark);
|
||||||
|
}
|
||||||
event->acceptProposedAction();
|
event->acceptProposedAction();
|
||||||
}
|
}
|
||||||
//! [dropEvent() function part3]
|
//! [dropEvent() function part3]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user