Problems with Open-Source Downloads read https://www.qt.io/blog/problem-with-open-source-downloads and https://forum.qt.io/post/638946
Неправильная обработка сигнала с клавиатуры
-
Всем привет :) прошу большой-большой помощи
И так: на форме qml присутствует виджет SpinBox, по дефолту у него значение от -800 до 800
Мне нужно чтобы ввод цифр с клавиатуры передавал в С++ его текущее значение, но проблема в том, что он его передаёт всегда 800 несмотря на то, что я ввел 123.
То-есть, прямо говоря, мне нужно сразу передавать текущее значение с SpinBox'а при каждом нажатии на цифру.
Вот код обработчика:
Keys.onReleased: { if(event.key === Qt.Key_1) { m_EQDrive.trackDEC(spBox_maxRate2.value * 15) event.accepted = true; } if(event.key === Qt.Key_2) { m_EQDrive.trackDEC(spBox_maxRate2.value * 15) event.accepted = true; } if(event.key === Qt.Key_3) { m_EQDrive.trackDEC(spBox_maxRate2.value * 15) event.accepted = true; } }
Вот код всего SpinBox'а:
SpinBox { id: spBox_maxRate2 x: 154 y: 127 width: 138 height: 42 from: -800 to: 800 value: 800 editable: true wheelEnabled: true wrap: true Material.accent: "#2196F3" Material.theme: Material.Dark Material.foreground: "white" Keys.onReleased: { if(event.key === Qt.Key_1) { m_EQDrive.trackDEC(spBox_maxRate2.value * 15) event.accepted = true; } if(event.key === Qt.Key_2) { m_EQDrive.trackDEC(spBox_maxRate2.value * 15) event.accepted = true; } if(event.key === Qt.Key_3) { m_EQDrive.trackDEC(spBox_maxRate2.value * 15) event.accepted = true; } } }
m_EQDrive - класс куда будет передаваться значение
Очень сильно буду благодарен за помощь :)
-
UPD:Пока кнопка Enter не будет нажата то новое значение не будет передано в класс, а нужно чтобы при каждом вводе цифры он передавал новую цифру.Как быть? :(Решил сам. Извините за костыли, но помощи не от кого было ждать
SpinBox { id: spBox_MaxRate anchors.centerIn: parent from: -800 to: 800 value: 800 editable: true wheelEnabled: true wrap: true Material.accent: "#2196F3" Material.theme: Material.Dark Material.foreground: "white" //Сигнал по изменению значений onValueChanged: { spinBoxValue = spBox_MaxRate.value * 15 } focus: true //Сигналы на нажатие кнопок Keys.onReleased: { if(event.key === Qt.Key_0) { //кнопка 0 spBox_MaxRate.focus = false spBox_MaxRate.focus = true event.accepted = true; } if(event.key === Qt.Key_1) { //кнопка 1 spBox_MaxRate.focus = false spBox_MaxRate.focus = true event.accepted = true; } if(event.key === Qt.Key_2) { //кнопка 2 spBox_MaxRate.focus = false spBox_MaxRate.focus = true event.accepted = true; } if(event.key === Qt.Key_3) { //кнопка 3 spBox_MaxRate.focus = false spBox_MaxRate.focus = true event.accepted = true; } if(event.key === Qt.Key_4) { //кнопка 4 spBox_MaxRate.focus = false spBox_MaxRate.focus = true event.accepted = true; } if(event.key === Qt.Key_5) { //кнопка 5 spBox_MaxRate.focus = false spBox_MaxRate.focus = true event.accepted = true; } if(event.key === Qt.Key_6) { //кнопка 6 spBox_MaxRate.focus = false spBox_MaxRate.focus = true event.accepted = true; } if(event.key === Qt.Key_7) { //кнопка 7 spBox_MaxRate.focus = false spBox_MaxRate.focus = true event.accepted = true; } if(event.key === Qt.Key_8) { //кнопка 8 spBox_MaxRate.focus = false spBox_MaxRate.focus = true event.accepted = true; } if(event.key === Qt.Key_9) { //кнопка 9 spBox_MaxRate.focus = false spBox_MaxRate.focus = true event.accepted = true; } if(event.key === Qt.Key_Backspace) { spBox_MaxRate.focus = false spBox_MaxRate.focus = true event.accepted = true; } if(event.key === Qt.Key_Delete) { spBox_MaxRate.focus = false spBox_MaxRate.focus = true event.accepted = true; } } //=================== //Выделение значений мышкой contentItem: TextInput { inputMethodHints: Qt.ImhFormattedNumbersOnly selectByMouse: true text: parent.textFromValue(parent.value, parent.locale) font.pointSize: 13 horizontalAlignment: Text.AlignHCenter color: "white" selectedTextColor: "black" selectionColor: "white" } onFocusChanged: { console.log("Focus changed") //Вывод значения когда фокус виджета будет в true if(spBox_MaxRate.focus === true) { spinBoxValue = spBox_MaxRate.value * 15 console.log("Value: " + spinBoxValue) } } }
spinBoxValue это переменная property real spinBoxValue
-
UPD:Пока кнопка Enter не будет нажата то новое значение не будет передано в класс, а нужно чтобы при каждом вводе цифры он передавал новую цифру.Как быть? :(Решил сам. Извините за костыли, но помощи не от кого было ждать
SpinBox { id: spBox_MaxRate anchors.centerIn: parent from: -800 to: 800 value: 800 editable: true wheelEnabled: true wrap: true Material.accent: "#2196F3" Material.theme: Material.Dark Material.foreground: "white" //Сигнал по изменению значений onValueChanged: { spinBoxValue = spBox_MaxRate.value * 15 } focus: true //Сигналы на нажатие кнопок Keys.onReleased: { if(event.key === Qt.Key_0) { //кнопка 0 spBox_MaxRate.focus = false spBox_MaxRate.focus = true event.accepted = true; } if(event.key === Qt.Key_1) { //кнопка 1 spBox_MaxRate.focus = false spBox_MaxRate.focus = true event.accepted = true; } if(event.key === Qt.Key_2) { //кнопка 2 spBox_MaxRate.focus = false spBox_MaxRate.focus = true event.accepted = true; } if(event.key === Qt.Key_3) { //кнопка 3 spBox_MaxRate.focus = false spBox_MaxRate.focus = true event.accepted = true; } if(event.key === Qt.Key_4) { //кнопка 4 spBox_MaxRate.focus = false spBox_MaxRate.focus = true event.accepted = true; } if(event.key === Qt.Key_5) { //кнопка 5 spBox_MaxRate.focus = false spBox_MaxRate.focus = true event.accepted = true; } if(event.key === Qt.Key_6) { //кнопка 6 spBox_MaxRate.focus = false spBox_MaxRate.focus = true event.accepted = true; } if(event.key === Qt.Key_7) { //кнопка 7 spBox_MaxRate.focus = false spBox_MaxRate.focus = true event.accepted = true; } if(event.key === Qt.Key_8) { //кнопка 8 spBox_MaxRate.focus = false spBox_MaxRate.focus = true event.accepted = true; } if(event.key === Qt.Key_9) { //кнопка 9 spBox_MaxRate.focus = false spBox_MaxRate.focus = true event.accepted = true; } if(event.key === Qt.Key_Backspace) { spBox_MaxRate.focus = false spBox_MaxRate.focus = true event.accepted = true; } if(event.key === Qt.Key_Delete) { spBox_MaxRate.focus = false spBox_MaxRate.focus = true event.accepted = true; } } //=================== //Выделение значений мышкой contentItem: TextInput { inputMethodHints: Qt.ImhFormattedNumbersOnly selectByMouse: true text: parent.textFromValue(parent.value, parent.locale) font.pointSize: 13 horizontalAlignment: Text.AlignHCenter color: "white" selectedTextColor: "black" selectionColor: "white" } onFocusChanged: { console.log("Focus changed") //Вывод значения когда фокус виджета будет в true if(spBox_MaxRate.focus === true) { spinBoxValue = spBox_MaxRate.value * 15 console.log("Value: " + spinBoxValue) } } }
spinBoxValue это переменная property real spinBoxValue