qml:FocusInput、TextInput 键盘输入

 有2个输入框,默认焦点在第一个输入框,按Tab键可以在两个输入框之间来回切换。

FocusInput.qml

import QtQuick

FocusScope {    //显式创建焦点范围
    width: 200
    height: 40
    x: 20
    y: 20

    property alias text: input.text
    property alias input: input

    Rectangle {
        id: rect
        border.color: 'gray'
        border.width: 2
        radius: 7
        anchors.fill: parent

        /*TextEdit*/ TextInput {    //二者的区别是:TextEdit是多行文本,TextInput是单行文本
            id: input
            anchors.left: parent.left
            anchors.verticalCenter: parent.verticalCenter
            anchors.margins: 6
            focus: true

            // wrapMode: Text.WordWrap //自动换行开启
        }
    }
}

05.qml 

import QtQuick

Window {
    width: 640
    height: 480
    visible: true
    title: qsTr("2.9 键盘输入")

    FocusInput {
        id: input1
        text: '你是小黑子吗?'
        input.font.pixelSize: 14 //设置字体大小
        height: input.font.pixelSize +20 //输入的高度

        focus: true //启用焦点
        KeyNavigation.tab: input2 //绑定Tab键切换焦点
    }

    FocusInput {
        id: input2
        text: '我不是!'
        input.font.pixelSize: 14
        height: input.font.pixelSize +20

        y: input1.y + input1.height +10 //加个间隙

        KeyNavigation.tab: input1
    }
}

相关推荐

  1. Android 8.1 实体键盘输入时收起软键盘

    2024-01-24 04:36:04       39 阅读
  2. 利用python进行键盘模拟输入

    2024-01-24 04:36:04       41 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-01-24 04:36:04       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-01-24 04:36:04       101 阅读
  3. 在Django里面运行非项目文件

    2024-01-24 04:36:04       82 阅读
  4. Python语言-面向对象

    2024-01-24 04:36:04       91 阅读

热门阅读

  1. Docker教程

    2024-01-24 04:36:04       44 阅读
  2. 在Kubernetes(K8s)中,CPU和内存的单位

    2024-01-24 04:36:04       62 阅读
  3. 多个coco数据标注文件合并

    2024-01-24 04:36:04       53 阅读
  4. 【Backbone】Vim(Vision Mamba)架构学习笔记

    2024-01-24 04:36:04       63 阅读
  5. 采用ERNIE计算 Perplexity (PPL)

    2024-01-24 04:36:04       50 阅读
  6. C#partial关键字(分布类)

    2024-01-24 04:36:04       49 阅读
  7. Structured Streaming基础--学习笔记

    2024-01-24 04:36:04       58 阅读