本文介绍了Qt 虚拟键盘 [PyQt 5.8]- 找不到样式,无法调整虚拟键盘的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用 Qt 虚拟键盘,它一直很顺利,直到...

问题在于:

  1. 正在设置环境变量.(有点检查)
  2. QT_VIRTUALKEYBOARD_STYLE(未找到).我已经从另一个 stackoverflow 帖子中创建了自己的样式,看起来不错,但是没有找到.

警告:找不到样式.../INTERACT/interact-ii/tools/en_GB/customkb.qml"-回退:默认"

一些尝试:

  1. 已将 customkeyboard.qml 单独文件放在我自己的项目中,并将变量设置为其路径.
  2. 已将默认 Qt 文件夹中的整个文件夹en_GB"放入我的项目中,并进行了修改.
  3. 还使用我的风格使用 Qt 文件夹中的原始路径设置了变量.
  4. 下载 Qt 5.8/5.7/5.6 并对所有 qtvirtualkeyboard 执行相同操作.
  5. 在看到上述错误(后备:默认")后,我尝试将我的 qml 项目添加到 qt 文件夹中的 default.qml.[.../Qt/5.8/Src/qtvirtualkeyboard/src/virtualkeyboard/content/styles/default]
  6. 已使用 QTCreator 打开 qtvirtualkeyboard.so 文件,并在更改我的 qml 文件后构建所有文件,以查看它是否会更改某些内容而没有任何更改.

它们似乎都没有修改我的键盘大小和位置.

这里有一个小例子很重要的文件.

1 - 使用键盘的小例子.

导入操作系统导入系统从 PyQt5.QtCore 导入 QProcessEnvironment从 PyQt5.QtWidgets 导入 QApplication从 PyQt5.QtWidgets 导入 QLineEdit从 PyQt5.QtWidgets 导入 QMainWindow从 PyQt5.QtWidgets 导入 QVBoxLayout从 PyQt5.QtWidgets 导入 QWidgetos.environ["QT5DIR"] = "/home/epson/Qt/5.8/gcc_64"os.environ["QT_QPA_PLATFORM_PLUGIN_PATH"] = "/home/epson/Qt/5.8/gcc_64/plugins/platforms"os.environ["QT_PLUGIN_PATH"] = "/home/epson/Qt/5.8/gcc_64/plugins"os.environ["QML_IMPORT_PATH"] = "/home/epson/Qt/5.8/gcc_64/qml"os.environ["QML2_IMPORT_PATH"] = "/home/epson/Qt/5.8/gcc_64/qml"os.environ["QT_VIRTUALKEYBOARD_LAYOUT_PATH"] = "/home/epson/INTERACT/interact-ii/tools/en_GB/customkb.qml"os.environ["QT_VIRTUALKEYBOARD_STYLE"] = "/home/epson/Qt/5.8/Src/qtvirtualkeyboard/src/virtualkeyboard/content/styles"os.environ["QT_IM_MODULE"] = "qtvirtualkeyboard"对于 QProcessEnvironment.systemEnvironment().keys() 中的 i:打印(一)类 MainWindow(QMainWindow):def __init__(self):super(MainWindow, self).__init__()self.line_edit = 无self.init_ui()定义 init_ui(self):self.line_edit = QLineEdit()self.line_edit2 = QLineEdit()self.layout = QVBoxLayout()self.main_widget = QWidget()self.main_widget.setLayout(self.layout)self.layout.addWidget(self.line_edit)self.layout.addWidget(self.line_edit2)self.setCentralWidget(self.main_widget)如果 __name__ == "__main__":app = QApplication(sys.argv)mw = 主窗口()mw.show()sys.exit(app.exec_())

2 - 我的 customkeyboard.qml

/*************************************************************************************** 版权所有 (C) 2016 The Qt Company Ltd.** 联系方式:https://www.qt.io/licensing/**** 该文件是 Qt Toolkit 的 Qt Virtual Keyboard 模块的一部分.**** $QT_BEGIN_LICENSE:GPL$** 商业许可证使用** 持有有效商业 Qt 许可证的被许可人可以在** 根据随附提供的商业许可协议** 软件,或者,根据包含在** 您与 Qt 公司之间的书面协议.对于许可条款** 和条件见 https://www.qt.io/terms-conditions.为了更进一步的** 信息使用 https://www.qt.io/contact-us 上的联系表.**** GNU 通用公共许可证使用** 或者,这个文件可以在 GNU 的条款下使用** 通用公共许可证版本 3 或(由您选择)任何更高版本** 由 KDE 免费 Qt 基金会批准.许可证是由发布的** 自由软件基金会并出现在文件 LICENSE.GPL3 中** 包含在此文件的包装中.请查看以下内容** 确保 GNU 通用公共许可证要求的信息** 满足:https://www.gnu.org/licenses/gpl-3.0.html.**** $QT_END_LICENSE$**************************************************************************************/导入 QtQuick 2.0导入 QtQuick.Window 2.2导入 QtQuick.VirtualKeyboard 2.1导入内容"物品 {宽度:1280高度:720物品 {id:应用容器宽度:屏幕宽度<屏幕高度?parent.height : parent.width高度:屏幕宽度<屏幕高度?parent.width : parent.heightanchors.centerIn:父级旋转:屏幕宽度<屏幕高度?90 : 0基本的 {id:虚拟键盘anchors.left: parent.leftanchors.top: parent.topanchors.right: parent.right锚点.底部:inputPanel.top}/* 用于全屏手写输入的手写输入面板.此组件是 InputPanel 组件的可选附加组件,即即,它的使用不影响InputPanel组件的运行,但它也不能用作独立组件.手写输入面板的位置覆盖整个区域应用.面板本身是透明的,但是一旦它处于活动状态用户可以在上面画笔迹.*/手写输入面板{z: 79id:手写输入面板anchors.fill:父级输入面板:输入面板长方形 {z:-1anchors.fill:父级颜色:黑色"不透明度:0.10}}/* 手写模式按钮的容器区域.手写模式按钮可以在容器区域内自由移动.在此示例中,单击更改手写模式和双击更改全屏手写输入的可用性.*/物品 {z: 89可见:handwritingInputPanel.enabled &&Qt.inputMethod.visible锚{左:parent.left;顶部:parent.top;权利:父母权利;底部:inputPanel.top;}手写模式按钮 {id:手写模式按钮anchors.top: parent.topanchors.right: parent.right锚点.边距:10浮动:真实可翻转:真实宽度:76高度宽度状态:handwritingInputPanel.stateonClicked: handwritingInputPanel.active = !handwritingInputPanel.activeonDoubleClicked: handwritingInputPanel.available = !handwritingInputPanel.available}}/* 键盘输入面板.键盘固定在应用程序的底部.*/输入面板{id:键盘;y:屏幕高度;//将键盘的顶部定位到屏幕/显示器的底部锚点.左:父母.左;anchors.right: parent.right;状态:状态{名称:可见";什么时候:keyboard.active;属性更改{目标:键盘;//将键盘的顶部定位到文本输入字段的底部y: textInput.height;}}过渡:过渡{从: "";//默认初始状态到:可见";可逆的:真;//使用可逆切换可见性:true;并行动画{数字动画{属性:y";持续时间:250;easing.type: Easing.InOutQuad;}}}}}}

问题:

我在设置 STYLE 和 LAYOUT 变量方面做错了吗?我应该真正设置其中的哪一个,是 STYLE 还是 LAYOUT 变量会改变我的键盘的大小和位置?我应该把 qml 文件放在哪里?我究竟做错了什么?看不出来是什么问题!!

Obs:即使遵循这个帖子也无法让它发挥作用.一切都完全一样,但似乎缺少某些东西,或者我误解了某些东西.

解决方案

我相信您对样式的布局感到困惑,这给您带来了几个问题.

布局

  1. en_GB 目录中的 .qml 文件是 Qt 用于键盘布局的文件.
  2. 要包含您的自定义布局,您必须将 QT_VIRTUALKEYBOARD_LAYOUT_PATH 变量指向您为自定义布局创建的目录(例如 QT_VIRTUALKEYBOARD_LAYOUT_PATH=/path/to/custom/keyboard-layout/mycustomlayout).然后,要为英式英语添加自定义布局,您需要在/path/to/custom/keyboard-layout/mycustomlayout 中创建一个 en_GB 目录.在您的 en_GB 目录中,您至少应该有 main.qml.
  3. 您已将文件命名为 customkeyboard.qml.为了让 Qt 正确定位、加载和处理您的自定义布局,您必须遵循默认布局的文件命名约定(即 main.qml、handwriting.qml、symbols.qml),如引用 此处.

样式

对于自定义样式,您必须将自定义样式目录放在 $$[QT_INSTALL_QML]/QtQuick/VirtualKeyboard/Styles 中,参考 此处.显然,您的自定义 style.qml 文件位于您的自定义样式目录中.

希望这有助于为您澄清一些事情.

I have been trying to work with Qt Virtual Keyboard and it has been going pretty good, until...


The problem is:

  1. Environment variables being set. (kinda check)
  2. QT_VIRTUALKEYBOARD_STYLE(not found). I've already created my own style, from another stackoverflow post, seems pretty good, but it's not being found.

Some attempts:

  1. Have put the customkeyboard.qml alone file inside my own project and set the variable to its path.
  2. Have put the whole folder "en_GB" from the default Qt folder inside my project with my modification.
  3. Have also set the variable with the original path from the Qt folder with my style.
  4. Downloaded Qt 5.8/5.7/5.6 and did the same for all the qtvirtualkeyboard.
  5. After seen the above error (fallback: "default") I tried to add my qml items to the default.qml from the qt folder. [.../Qt/5.8/Src/qtvirtualkeyboard/src/virtualkeyboard/content/styles/default]
  6. Have opened the qtvirtualkeyboard.so file with QTCreator and build all after changing my qml files also to see if it would change something and nothing changed.

None of them seems to modify my keyboard size and location.


Here are the files that matter with a small example.

1 - Small example using the keyboard.

import os
import sys

from PyQt5.QtCore import QProcessEnvironment
from PyQt5.QtWidgets import QApplication
from PyQt5.QtWidgets import QLineEdit
from PyQt5.QtWidgets import QMainWindow
from PyQt5.QtWidgets import QVBoxLayout
from PyQt5.QtWidgets import QWidget

os.environ["QT5DIR"] = "/home/epson/Qt/5.8/gcc_64"
os.environ["QT_QPA_PLATFORM_PLUGIN_PATH"] = "/home/epson/Qt/5.8/gcc_64/plugins/platforms"
os.environ["QT_PLUGIN_PATH"] = "/home/epson/Qt/5.8/gcc_64/plugins"
os.environ["QML_IMPORT_PATH"] = "/home/epson/Qt/5.8/gcc_64/qml"
os.environ["QML2_IMPORT_PATH"] = "/home/epson/Qt/5.8/gcc_64/qml"

os.environ["QT_VIRTUALKEYBOARD_LAYOUT_PATH"] = "/home/epson/INTERACT/interact-ii/tools/en_GB/customkb.qml"
os.environ["QT_VIRTUALKEYBOARD_STYLE"] = "/home/epson/Qt/5.8/Src/qtvirtualkeyboard/src/virtualkeyboard/content/styles"
os.environ["QT_IM_MODULE"] = "qtvirtualkeyboard"

for i in QProcessEnvironment.systemEnvironment().keys():
    print(i)

class MainWindow(QMainWindow):

    def __init__(self):
        super(MainWindow, self).__init__()
        self.line_edit = None


        self.init_ui()

    def init_ui(self):
        self.line_edit = QLineEdit()
        self.line_edit2 = QLineEdit()
        self.layout = QVBoxLayout()
        self.main_widget = QWidget()
        self.main_widget.setLayout(self.layout)
        self.layout.addWidget(self.line_edit)
        self.layout.addWidget(self.line_edit2)
        self.setCentralWidget(self.main_widget)


if __name__ == "__main__":
    app = QApplication(sys.argv)
    mw = MainWindow()
    mw.show()
    sys.exit(app.exec_())

2 - My customkeyboard.qml

/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt Virtual Keyboard module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:GPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 or (at your option) any later version
** approved by the KDE Free Qt Foundation. The licenses are as published by
** the Free Software Foundation and appearing in the file LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

import QtQuick 2.0
import QtQuick.Window 2.2
import QtQuick.VirtualKeyboard 2.1
import "content"

Item {
    width: 1280
    height: 720

    Item {
        id: appContainer
        width: Screen.width < Screen.height ? parent.height : parent.width
        height: Screen.width < Screen.height ? parent.width : parent.height
        anchors.centerIn: parent
        rotation: Screen.width < Screen.height ? 90 : 0
        Basic {
            id: virtualKeyboard
            anchors.left: parent.left
            anchors.top: parent.top
            anchors.right: parent.right
            anchors.bottom: inputPanel.top
        }

        /*  Handwriting input panel for full screen handwriting input.

            This component is an optional add-on for the InputPanel component, that
            is, its use does not affect the operation of the InputPanel component,
            but it also can not be used as a standalone component.

            The handwriting input panel is positioned to cover the entire area of
            application. The panel itself is transparent, but once it is active the
            user can draw handwriting on it.
        */
        HandwritingInputPanel {
            z: 79
            id: handwritingInputPanel
            anchors.fill: parent
            inputPanel: inputPanel
            Rectangle {
                z: -1
                anchors.fill: parent
                color: "black"
                opacity: 0.10
            }
        }

        /*  Container area for the handwriting mode button.

            Handwriting mode button can be moved freely within the container area.
            In this example, a single click changes the handwriting mode and a
            double-click changes the availability of the full screen handwriting input.
        */
        Item {
            z: 89
            visible: handwritingInputPanel.enabled && Qt.inputMethod.visible
            anchors { left: parent.left; top: parent.top; right: parent.right; bottom: inputPanel.top; }
            HandwritingModeButton {
                id: handwritingModeButton
                anchors.top: parent.top
                anchors.right: parent.right
                anchors.margins: 10
                floating: true
                flipable: true
                width: 76
                height: width
                state: handwritingInputPanel.state
                onClicked: handwritingInputPanel.active = !handwritingInputPanel.active
                onDoubleClicked: handwritingInputPanel.available = !handwritingInputPanel.available
            }
        }

        /*  Keyboard input panel.

            The keyboard is anchored to the bottom of the application.
        */
        InputPanel {
            id: keyboard;
            y: screenHeight; // position the top of the keyboard to the bottom of the screen/display

            anchors.left: parent.left;
            anchors.right: parent.right;

            states: State {
                name: "visible";
                when: keyboard.active;
                PropertyChanges {
                    target: keyboard;
                    // position the top of the keyboard to the bottom of the text input field
                    y: textInput.height;
                }
            }
            transitions: Transition {
                from: ""; // default initial state
                to: "visible";
                reversible: true; // toggle visibility with reversible: true;
                ParallelAnimation {
                    NumberAnimation {
                        properties: "y";
                        duration: 250;
                        easing.type: Easing.InOutQuad;
                    }
                }
            }
        }
    }
}

QUESTION:

Am I doing things wrongly about setting STYLE and LAYOUT variables? Which one of them both should I really been setting up, is it the STYLE or the LAYOUT variable that would change the size and location of my keyboard? Where should I really put the qml file? What am I doing wrong? Can't see what is the problem!!

Obs: Even following this post couldn't make it work. Did everything exactly the same but seems something is missing or I'm misunderstanding something.

解决方案

I believe you are confusing layouts for styles which is creating several problems for you.

Layouts

  1. The .qml files in the en_GB directory are what Qt uses for the keyboard layout.
  2. To include your custom layouts, you must point the QT_VIRTUALKEYBOARD_LAYOUT_PATH var to the directory you created for your custom layouts (e.g. QT_VIRTUALKEYBOARD_LAYOUT_PATH=/path/to/custom/keyboard-layout/mycustomlayout). Then, to add a custom layout for British English, you would create a en_GB directory in /path/to/custom/keyboard-layout/mycustomlayout. In your en_GB directory, you should have, at the very least, main.qml.
  3. You have named your file customkeyboard.qml. In order for Qt to correctly locate, load, and process your custom layout, you must follow the file naming convention of the default layouts (i.e. main.qml, handwriting.qml, symbols.qml), as referenced here.

Styles

For custom styles, you must put your custom style directory in $$[QT_INSTALL_QML]/QtQuick/VirtualKeyboard/Styles, as referenced here. Obviously, your custom style.qml file goes in your custom style directory.

Hopefully that helps clarify some things for you.

这篇关于Qt 虚拟键盘 [PyQt 5.8]- 找不到样式,无法调整虚拟键盘的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 02:54