mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-04 02:39:28 +00:00
platform_qt example: implement clipboard
This commit is contained in:
parent
d160eb7a31
commit
9c3cba0c50
1 changed files with 33 additions and 0 deletions
|
@ -335,6 +335,39 @@ struct MyPlatform : public slint::platform::Platform
|
|||
{
|
||||
return std::make_unique<MyWindow>(parentWindow.get());
|
||||
}
|
||||
|
||||
void set_clipboard_text(const slint::SharedString &str,
|
||||
slint::platform::Platform::Clipboard clipboard) override
|
||||
{
|
||||
switch (clipboard) {
|
||||
case slint::platform::Platform::Clipboard::DefaultClipboard:
|
||||
qApp->clipboard()->setText(QString::fromUtf8(str.data()), QClipboard::Clipboard);
|
||||
break;
|
||||
case slint::platform::Platform::Clipboard::SelectionClipboard:
|
||||
qApp->clipboard()->setText(QString::fromUtf8(str.data()), QClipboard::Selection);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<slint::SharedString> clipboard_text(Clipboard clipboard) override
|
||||
{
|
||||
QString text;
|
||||
switch (clipboard) {
|
||||
case slint::platform::Platform::Clipboard::DefaultClipboard:
|
||||
text = qApp->clipboard()->text(QClipboard::Clipboard);
|
||||
break;
|
||||
case slint::platform::Platform::Clipboard::SelectionClipboard:
|
||||
text = qApp->clipboard()->text(QClipboard::Selection);
|
||||
break;
|
||||
default:
|
||||
return {};
|
||||
}
|
||||
if (text.isNull()) {
|
||||
return {};
|
||||
} else {
|
||||
return slint::SharedString(text.toUtf8().data());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, char **argv)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue