【问题标题】:Show VirtualKeyboard in Dialog在对话框中显示虚拟键盘
【发布时间】:2020-05-16 17:20:08
【问题描述】:

我正在使用带有 qml 的 qtvirtualkeyboard 模块。我使用以下 qml 代码来显示虚拟键盘。

import QtQuick 2.5
import QtQuick.VirtualKeyboard 2.1

    InputPanel {
        id: inputPanel
        y: Qt.inputMethod.visible ? parent.height - inputPanel.height : parent.height
        anchors.left: parent.left
        anchors.right: parent.right
        focus: true
    }

当我在模态配置为 true 的对话框中调用该 qml 时,我无法触摸键盘。如果对话框模式配置为假,那么我可以触摸键盘,但这次对话框是隐藏的。另外我希望用户只能控制对话框屏幕上的键盘。

如何控制对话屏幕上的虚拟键盘?

【问题讨论】:

    标签: qt qml qtvirtualkeyboard


    【解决方案1】:

    如果我正确理解了这个问题,那么这很可能与QTBUG-56918 是同一个问题。正如 JP 在该错误报告的 cmets 中所提到的,一种可能的解决方法(对于 Qt Quick Controls 2 应用程序)是在 InputPanel 上设置 parent: root.overlayz: 1 以将其提升到弹出窗口(或对话框)上方。

    【讨论】:

    • 我已经尝试过了,但它不适用于对话。所以我将我的对话框转换为 Popup 及其工作。谢谢。
    【解决方案2】:

    为 InputPanel 设置以下属性:

    z: 1
    parent: Overlay.overlay
    focus: true
    

    并为 Popup 设置以下属性:

    modal: false
    focus: true
    

    【讨论】:

      【解决方案3】:

      如果您想为多个不同的对话框提供可重用的解决方案,将键盘设为对话框的子项会给您带来压力。因此,我的解决方法是使用带有 MouseArea 的非模态对话框,它可以被实例化并用作对话框(但使用别名属性而不是 Item 的):

      ModalDialog.qml:

      Item {
        anchors.fill: parent
        property alias title: dialog.title
        property alias _x: dialog.x
        property alias _y: dialog.y
        property alias _width: dialog.width
        property alias _height: dialog.height
        property alias closePolicy: dialog.closePolicy
        property alias standardButtons: dialog.standardButtons
        default property alias contentData: dialog.contentData
        property alias _visible: dialog.visible
        visible: _visible
        function open() { dialog.open() }
      
        Dialog {
          id: dialog
        }
        MouseArea {
          anchors.fill: parent
          z: 100
        }
        Rectangle {
          anchors.fill: parent
          color: "black"
          opacity: dialog.opacity / 2
          z: 100
        }
      }
      

      【讨论】:

        猜你喜欢
        • 2020-10-09
        • 2017-07-16
        • 1970-01-01
        • 1970-01-01
        • 2012-10-21
        • 2014-07-03
        • 2015-01-02
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多