QtVirtualKeyboard 虚拟键盘美化

源码的界面式样太丑,不符合产品设计风格,所有花了半天时间美化了一下,直接上效果:

1.键盘显示位置和大小修改修改这段代码,让键盘显示宽2/3屏幕,并且处于底部居中

void DesktopInputPanel::show()
{
    AppInputPanel::show();
    Q_D(DesktopInputPanel);
    if (d->view) {
        QRect rc=QGuiApplication::primaryScreen()->geometry();

        rc.moveTo(rc.width()*1/6,rc.height()*1/3);
        rc.setWidth(rc.width()*2/3);
        rc.setHeight(rc.height()*2/3);
        repositionView(rc);
        d->view->show();
    }
}

2.style.qml修改按钮的式样 ,修改文字显示颜色,修改底图

 

keyPanel: KeyPanel {
        Rectangle {
            id: keyBackground
            color: "#344D61"
            anchors.fill: parent
            anchors.margins: keyBackgroundMargin
            radius: 10
            BorderImage {
                id: keyBorderImage
                border { left: 30; top: 30; right: 30; bottom: 30 }
                horizontalTileMode: BorderImage.Stretch
                verticalTileMode: BorderImage.Stretch
                anchors.fill: parent
                source: resourcePrefix + "images/btn_jp.png"
            }
            Text {
                id: keySmallText
                text: control.smallText
                visible: control.smallTextVisible
                color: "#547A99"
                anchors.right: parent.right
                anchors.top: parent.top
                anchors.margins: keyContentMargin / 3
                font {
                    family: fontFamily
                    weight: Font.Normal
                    pixelSize: 38 * scaleHint
                    capitalization: control.uppercased ? Font.AllUppercase : Font.MixedCase
                }
            }
            Text {
                id: keyText
                text: control.displayText
                color: "#547A99"
                horizontalAlignment: Text.AlignHCenter
                verticalAlignment: Text.AlignVCenter
                anchors.fill: parent
                anchors.leftMargin: keyContentMargin
                anchors.topMargin: control.smallTextVisible ? keyContentMargin * 1.2 : keyContentMargin
                anchors.rightMargin: keyContentMargin
                anchors.bottomMargin: control.smallTextVisible ? keyContentMargin * 0.8 : keyContentMargin
                font {
                    family: fontFamily
                    weight: Font.Normal
                    pixelSize: 52 * scaleHint
                    capitalization: control.uppercased ? Font.AllUppercase : Font.MixedCase
                }
            }
        }
        states: [
            State {
                name: "pressed"
                when: control.pressed
                //PropertyChanges {
                //    target: keyBackground
                //    opacity: 0.75
                //}
                PropertyChanges {
                    target: keyText
                    opacity: 0.5
                }
                PropertyChanges {
                    target: keyBorderImage
                    source: resourcePrefix + "images/btn_jp_pre.png"
                }

            },
            State {
                name: "disabled"
                when: !control.enabled
                PropertyChanges {
                    target: keyBackground
                    opacity: 0.75
                }
                PropertyChanges {
                    target: keyText
                    opacity: 0.05
                }
            }
        ]
    }

3.修改按钮大小、间隔,没时间做了,大家可以试试

 

KDE的QtVirtualKeyboard是一个基于Qt库的轻量级虚拟键盘解决方案,它允许用户在需要输入文本的非文本字段上弹出虚拟键盘。尽管具体的代码细节可能会随着版本变化而有所不同,但是基本框架通常涉及以下几个步骤: 1. **QML组件**:在Qt Quick应用程序中,创建一个`QQuickItem`的子类,比如`KVirtualKeyboard.qml`,作为键盘的显示层。 ```qml import QtQuick 2.0 import QtQuick.Input 2.0 Item { id: keyboard width: parent.width height: parent.height // 添加按键布局、触摸事件处理等 } ``` 2. **触摸处理**:添加触摸事件处理器,当屏幕触摸时切换到键盘显示,并在手指移动时调整键盘位置。 ```qml onTouchMove: { if (touch.phase == TouchPhase.Began) { show(); } else if (touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Moved) { hide(); } } ``` 3. **键盘逻辑**:在`KVirtualKeyboard.qml`中管理按键状态和文本输入,这可能涉及到`TextInput`组件的连接,以及键盘的隐藏和显示功能。 4. **数据绑定**:通过数据绑定将用户的输入与目标控件关联起来,以便实时更新文本内容。 5. **自定义功能**:可以扩展键盘以支持特殊字符、表情或其他语言。 请注意,由于源代码的开源性质,你可以在KDE的Git仓库中找到相关的实现代码,如[这里](https://github.com/KDE/plasma-workspace/tree/master/plasma-keyboard/qml/org.kde.plasma.keyboard)。实际查看代码时,你可能需要熟悉Qt的信号槽机制以及QML的语法。
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值