@Michael
Я пишу код клавиатуры и у меня он просто перестал отображаться
I write the keyboard code and it just stops displaying for me
kbtest.flp (11.5 KB)
Я думаю, что ошибка в самом коде, помогите ее найти…
I think there is a mistake in the code itself, help me find it…
import QtQuick 2.15
import QtQuick.Window 2.15
import QtQuick.Layouts 1.12
import QtQuick.Controls 2.15
Item {
property int maxButtonWidth: Math.min(width / 11, 60) // Максимальный размер кнопки
property bool isUpperCase: false
property string currentLayout: "ru"
property string currentNumber: "nu"
ColumnLayout {
anchors.fill: parent
spacing: 20
RowLayout {
Layout.alignment: Qt.AlignHCenter
Layout.fillWidth: true
spacing: 30
Button {
text: "EN/RU"
implicitWidth: 80
implicitHeight: 40
background: Rectangle {
anchors.fill: parent
color: "darkgray" // Цвет фона кнопки
border.color: "darkgray"
}
onClicked: switchLayout()
}
Repeater {
model: currentNumber === "nu" ? ["#!?"] : ["123"]
delegate: Button {
implicitWidth: 80
implicitHeight: 40
text: modelData
Layout.preferredWidth: maxButtonWidth
background: Rectangle {
anchors.fill: parent
color: "darkgray" // Цвет фона кнопки
border.color: "darkgray"
}
onClicked: switchNumber()
}
}
Repeater {
model: currentNumber === "nu" ? ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"] :
["!", "?", "#", "$", "%", "^", "&&", "*", "(", ")"]
delegate: Button {
text: modelData
Layout.preferredWidth: maxButtonWidth
onClicked: keyPress(text)
}
}
}
RowLayout {
Layout.alignment: Qt.AlignHCenter
Layout.fillWidth: true
spacing: 30
Repeater {
model: if(currentNumber === "si") {["{", "}", "[", "]", ";", ":", "\'", "\"", "\\", "\/", "@", "|"] } else {if (!isUpperCase) {currentLayout === "ru" ?
["й", "ц", "у", "к", "е", "н", "г", "ш", "щ", "з", "х", "ъ"] :
["q", "w", "e", "r", "t", "y", "u", "i", "o", "p"]} else{
currentLayout === "ru" ?
["Й", "Ц", "У", "К", "Е", "Н", "Г", "Ш", "Щ", "З", "Х", "Ъ"] :
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"] }
}
Button {
text: modelData
Layout.preferredWidth: maxButtonWidth
onClicked: keyPress(text)
}
}
}
RowLayout {
Layout.alignment: Qt.AlignHCenter
Layout.fillWidth: true
spacing: 30
Repeater {
model: if (!isUpperCase) { currentLayout === "ru" ? ["ф", "ы", "в", "а", "п", "р", "о", "л", "д", "ж", "э"] :
["a", "s", "d", "f", "g", "h", "j", "k", "l"]} else{
currentLayout === "ru" ?
["Ф", "Ы", "В", "А", "П", "Р", "О", "Л", "Д", "Ж", "Э"] :
["A", "S", "D", "F", "G", "H", "J", "K", "L"]}
Button {
text: modelData
Layout.preferredWidth: maxButtonWidth
onClicked: keyPress(text)
}
}
}
RowLayout {
Layout.alignment: Qt.AlignHCenter
Layout.fillWidth: true
spacing: 30
Repeater {
model: if (!isUpperCase) { currentLayout === "ru" ? ["я", "ч", "с", "м", "и", "т", "ь", "б", "ю"] :
["z", "x", "c", "v", "b", "n", "m"]} else{
currentLayout === "ru" ?
["Я", "Ч", "С", "М", "И", "Т", "Ь", "Б", "Ю"] :
["Z", "X", "C", "V", "B", "N", "M"]}
Button {
text: modelData
Layout.preferredWidth: maxButtonWidth
onClicked: keyPress(text)
}
}
}
RowLayout {
Layout.alignment: Qt.AlignHCenter
Layout.fillWidth: true
spacing: 50
Button {
text: "Shift"
Layout.preferredWidth: maxButtonWidth * 2
onClicked: toggleCase()
}
Button {
text: "Backspace"
Layout.preferredWidth: maxButtonWidth * 2
onClicked: backspace()
}
Button {
text: "Space"
Layout.preferredWidth: maxButtonWidth * 7
onClicked: keyPress(" ")
}
Button {
text: "Enter"
Layout.preferredWidth: maxButtonWidth * 2
onClicked: keyPress("")
}
}
}
function keyPress(charw) {
// if (isUpperCase && currentLayout === "ru") {charw = charw.toUpperCase();}
textField.text += charw;
}
function backspace() {
textField.text = textField.text.slice(0, -1);
}
function toggleCase() {
isUpperCase = !isUpperCase;
}
function switchNumber() {
currentNumber = currentNumber === "nu" ? "si" : "nu";
}
function switchLayout() {
currentLayout = currentLayout === "ru" ? "en" : "ru";
}
}