mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-04 18:58:36 +00:00
C++ platform Qt example: handle key events
This commit is contained in:
parent
a34074db11
commit
41f0972e4b
2 changed files with 15 additions and 7 deletions
|
@ -1,7 +1,7 @@
|
|||
// Copyright © SixtyFPS GmbH <info@slint.dev>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import {Button, AboutSlint} from "std-widgets.slint";
|
||||
import {Button, AboutSlint, LineEdit } from "std-widgets.slint";
|
||||
|
||||
export component App inherits Window {
|
||||
preferred-width: 800px;
|
||||
|
@ -15,6 +15,7 @@ export component App inherits Window {
|
|||
clicked => { count += 1; }
|
||||
}
|
||||
Text { text: count; }
|
||||
LineEdit {}
|
||||
Rectangle { }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,11 +54,17 @@ static slint::platform::NativeWindowHandle window_handle_for_qt_window(QWindow *
|
|||
native->nativeResourceForWindow(QByteArray("connection"), window))) {
|
||||
return slint::platform::NativeWindowHandle::from_x11_xcb(wid, wid, xcb_connection, screen);
|
||||
} else {
|
||||
throw "Unsupported windowing system (tried waylamd, xlib, and xcb)";
|
||||
throw "Unsupported windowing system (tried wayland, xlib, and xcb)";
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static slint::SharedString key_event_text(QKeyEvent *e)
|
||||
{
|
||||
// TODO: handle special keys
|
||||
return e->text().toUtf8().data();
|
||||
}
|
||||
|
||||
class MyWindow : public QWindow, public slint::platform::WindowAdapter
|
||||
{
|
||||
std::optional<slint::platform::SkiaRenderer> m_renderer;
|
||||
|
@ -72,11 +78,6 @@ public:
|
|||
|
||||
slint::platform::AbstractRenderer &renderer() override { return m_renderer.value(); }
|
||||
|
||||
/*void keyEvent(QKeyEvent *event) override
|
||||
{
|
||||
renderer()->dispatch_key_event(slint::cbingen_private::UglyEnum {... })
|
||||
}*/
|
||||
|
||||
void paintEvent(QPaintEvent *ev) override
|
||||
{
|
||||
slint::platform::update_timers_and_animations();
|
||||
|
@ -93,6 +94,12 @@ public:
|
|||
if (e->type() == QEvent::UpdateRequest) {
|
||||
paintEvent(static_cast<QPaintEvent *>(e));
|
||||
return true;
|
||||
} else if (e->type() == QEvent::KeyPress) {
|
||||
window().dispatch_key_press_event(key_event_text(static_cast<QKeyEvent *>(e)));
|
||||
return true;
|
||||
} else if (e->type() == QEvent::KeyRelease) {
|
||||
window().dispatch_key_release_event(key_event_text(static_cast<QKeyEvent *>(e)));
|
||||
return true;
|
||||
} else {
|
||||
return QWindow::event(e);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue