fix(slint): single click on button primitives (FocusScope stole the first press)
Slint hit-tests sibling children in reverse declaration order, so the keyboard FocusScope declared after the pointer TouchArea was visited first and, with the default focus-on-click, consumed the first Pressed just to grab focus — aborting traversal before the TouchArea, so every button needed two clicks. Set focus-on-click: false on the FocusScope in QbzPrimaryButton, SecondaryButton, QbzCheckbox, QbzToggle, ToggleButton and QbzSelect; the press now reaches the TouchArea on the first click (Tab/Enter/Space activation unaffected). cc
This commit is contained in:
6 files changed
+28
-4
No files matched your search
@@ -35,6 +35,9 @@ export component QbzCheckbox inherits Rectangle {
|
||||
// Keyboard activation: Enter/Space toggle the box, same as a click. The
|
||||
// TouchArea stays the pointer source; this only adds key activation + focus.
|
||||
fs := FocusScope {
|
||||
// See QbzPrimaryButton: declared after `ta`, so Slint hit-tests it
|
||||
// first; focus-on-click:false stops it eating the first press.
|
||||
focus-on-click: false;
|
||||
key-pressed(event) => {
|
||||
if (event.text == Key.Return || event.text == " ") {
|
||||
root.checked = !root.checked;
|
||||
|
||||
@@ -50,10 +50,18 @@ export component QbzPrimaryButton inherits Rectangle {
|
||||
}
|
||||
}
|
||||
|
||||
// Keyboard activation: Enter/Space fire the same click. The TouchArea above
|
||||
// stays the pointer source; this only adds key activation + focusability.
|
||||
// Keyboard activation: Enter/Space fire the same click. `focus-on-click:
|
||||
// false` is LOAD-BEARING: Slint hit-tests siblings in REVERSE declaration
|
||||
// order, so this FocusScope (declared after `ta`) is visited BEFORE the
|
||||
// TouchArea. With the default focus-on-click:true an unfocused FocusScope
|
||||
// eats the first Pressed just to grab keyboard focus, aborting the event
|
||||
// before it reaches `ta` — THE "blue buttons need two clicks" bug. Disabling
|
||||
// focus-on-click makes the FocusScope ignore the press (it stays Tab- and
|
||||
// key-focusable for Enter/Space); the press then falls through to `ta` and
|
||||
// the first click registers.
|
||||
fs := FocusScope {
|
||||
enabled: root.enabled;
|
||||
focus-on-click: false;
|
||||
key-pressed(event) => {
|
||||
if (event.text == Key.Return || event.text == " ") {
|
||||
root.clicked();
|
||||
|
||||
@@ -160,6 +160,9 @@ export component QbzSelect inherits Rectangle {
|
||||
// focusability on the collapsed control.
|
||||
fs := FocusScope {
|
||||
enabled: root.enabled;
|
||||
// See QbzPrimaryButton: declared after `ta`, hit-tested first;
|
||||
// focus-on-click:false stops it eating the first press (two-click bug).
|
||||
focus-on-click: false;
|
||||
key-pressed(event) => {
|
||||
if (event.text == Key.Return || event.text == " ") {
|
||||
root.filter = "";
|
||||
|
||||
@@ -40,6 +40,9 @@ export component QbzToggle inherits Rectangle {
|
||||
// TouchArea stays the pointer source; this only adds key activation + focus.
|
||||
fs := FocusScope {
|
||||
enabled: root.enabled;
|
||||
// See QbzPrimaryButton: declared after `ta`, hit-tested first;
|
||||
// focus-on-click:false stops it eating the first press (two-click bug).
|
||||
focus-on-click: false;
|
||||
key-pressed(event) => {
|
||||
if (event.text == Key.Return || event.text == " ") {
|
||||
root.toggled(!root.checked);
|
||||
|
||||
@@ -48,10 +48,14 @@ export component SecondaryButton inherits Rectangle {
|
||||
}
|
||||
}
|
||||
|
||||
// Keyboard activation: Enter/Space fire the same click. The TouchArea stays
|
||||
// the pointer source; this only adds key activation + focusability.
|
||||
// Keyboard activation: Enter/Space fire the same click. `focus-on-click:
|
||||
// false` is LOAD-BEARING — see QbzPrimaryButton: Slint hit-tests siblings in
|
||||
// reverse declaration order, so this FocusScope (after `ta`) would otherwise
|
||||
// eat the first Pressed to grab focus, requiring a second click. Disabling
|
||||
// click-focus lets the press fall through to `ta` (Tab/Enter/Space stay).
|
||||
fs := FocusScope {
|
||||
enabled: root.enabled;
|
||||
focus-on-click: false;
|
||||
key-pressed(event) => {
|
||||
if (event.text == Key.Return || event.text == " ") {
|
||||
root.clicked();
|
||||
|
||||
@@ -40,6 +40,9 @@ export component ToggleButton inherits Rectangle {
|
||||
// Keyboard activation: Enter/Space fire the same click. The TouchArea stays
|
||||
// the pointer source; this only adds key activation + focusability.
|
||||
fs := FocusScope {
|
||||
// See QbzPrimaryButton: declared after `ta`, hit-tested first;
|
||||
// focus-on-click:false stops it eating the first press (two-click bug).
|
||||
focus-on-click: false;
|
||||
key-pressed(event) => {
|
||||
if (event.text == Key.Return || event.text == " ") {
|
||||
root.clicked();
|
||||
|
||||
Reference in new issue
Block a user