【问题标题】:Qt Virtual Keyboard [PyQt 5.8]- Style not being found, unable to resize virtual keyboardQt 虚拟键盘 [PyQt 5.8]- 找不到样式,无法调整虚拟键盘的大小
【发布时间】:2017-10-25 06:09:18
【问题描述】:

我一直在尝试使用 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 - 使用键盘的小例子。

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 - 我的 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;
                    }
                }
            }
        }
    }
}

问题:

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

Obs:即使关注此post 也无法使其工作。一切都完全相同,但似乎缺少某些东西或我误解了某些东西。

【问题讨论】:

    标签: python qt pyqt pyqt5


    【解决方案1】:

    我相信您混淆了样式的布局,这给您带来了一些问题。

    布局

    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),如引用 here。李>

    样式

    对于自定义样式,您必须将自定义样式目录放在 $$[QT_INSTALL_QML]/QtQuick/VirtualKeyboard/Styles 中,如引用 here。显然,您的自定义 style.qml 文件位于您的自定义样式目录中。

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

    【讨论】:

    • 哦,我想我知道当时和现在的区别了。只是为了确定,如果我想将我的键盘移动到不同的位置并改变它的大小,我应该使用自定义样式,对吗?剩下的我会想办法的。已经非常感谢您的回复。将尝试您的建议并返回")
    • 嘿,马特,我已经获得了 en_GB 布局,放入我的项目中,将 QT_VIRTUALKEYBOARD_LAYOUT_PATH 设置为我项目中的 en_GB 路径。我从这里迷路了,我应该把我的布局(位置和大小)放在哪里?我应该从 en_GB 编辑 main.qml,还是创建自己的 file.qml。路径应该来自整个文件夹,或者只是我想要的布局的 file.qml。从这里有点迷路了。
    • 我完全理解这种困惑。 Qt 中的语义很容易产生歧义。
    • 为了澄清,QT_VIRTUALKEYBOARD_LAYOUT_PATH 应设置为 en_GB 的包含文件夹。为了确认您已经为布局正确设置了所有内容,我只需交换main.qml 中的前两个键(例如,用“W”代替“Q”)来验证 Qt 是否使用了您想要的布局操纵。在style.qml 中定义位置、大小等。该文件应放在$$[QT_INSTALL_QML]/QtQuick/VirtualKeyboard/Styles/YourCustomStyleNameGoesHere/style.qml 中,QT_VIRTUALKEYBOARD_STYLE 设置为$$[QT_INSTALL_QML]/QtQuick/VirtualKeyboard/Styles/YourCustomStyleNameGoesHere
    • 您好,Matt,很抱歉打扰您,我的风格终于奏效了,但由于某种原因,我的布局与我使用 QT_VIRTUALKEYBOARD_LAYOUT_PATH 定义的布局不一致。但无论如何,因为我只想改变大小和位置并且它的风格,我为此付出了很多努力,我一直在搞乱 keyboardDesignWidth keyboardDesignHeight keyboardRelativetopMargin ......而且它们似乎都没有改变。我的布局变得疯狂,只有它的内部键改变大小和位置,而不是 kb 大小/位置本身。阅读应该在 InputPanel 中的某个地方,有什么建议吗?
    猜你喜欢
    • 1970-01-01
    • 2017-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多