Show focus for NativeComboBox

This commit is contained in:
notfirefox 2024-04-03 12:30:56 +00:00 committed by Olivier Goffart
parent 0cfeec1a31
commit e2aeb56263
3 changed files with 10 additions and 2 deletions

View file

@ -10,6 +10,7 @@ use super::*;
#[pin]
pub struct NativeComboBox {
pub enabled: Property<bool>,
pub has_focus: Property<bool>,
pub pressed: Property<bool>,
pub has_hover: Property<bool>,
pub is_open: Property<bool>,
@ -94,6 +95,7 @@ impl Item for NativeComboBox {
let text: qttypes::QString =
this.current_value().as_str().into();
let enabled = this.enabled();
let has_focus = this.has_focus();
let has_hover = this.has_hover();
cpp!(unsafe [
painter as "QPainterPtr*",
@ -103,6 +105,7 @@ impl Item for NativeComboBox {
size as "QSize",
down as "bool",
is_open as "bool",
has_focus as "bool",
has_hover as "bool",
dpr as "float",
initial_state as "int"
@ -122,6 +125,9 @@ impl Item for NativeComboBox {
} else {
option.palette.setCurrentColorGroup(QPalette::Disabled);
}
if (has_focus) {
option.state |= QStyle::State_HasFocus | QStyle::State_KeyboardFocusChange | QStyle::State_Item;
}
if (has_hover) {
option.state |= QStyle::State_MouseOver;
}

View file

@ -501,6 +501,7 @@ export component NativeTableHeaderSection {
export component NativeComboBox {
in-out property <string> current_value;
in property <bool> enabled: true;
in property <bool> has-focus;
//-is_internal
}

View file

@ -6,11 +6,11 @@ import { ComboBoxBase } from "../common/combobox-base.slint";
export component ComboBox inherits NativeComboBox {
in property <[string]> model <=> i-base.model;
in-out property <int> current-index <=> i-base.current-index;
out property has-focus <=> i-base.has-focus;
callback selected <=> i-base.selected;
enabled: true;
has-focus: i-base.has-focus;
accessible-role: combobox;
accessible-value <=> root.current-value;
current-value: root.model[root.current-index];
@ -53,4 +53,5 @@ export component ComboBox inherits NativeComboBox {
}
}
}
}
}