【问题标题】:MouseArea prevents editingMouseArea 防止编辑
【发布时间】:2016-09-05 18:10:09
【问题描述】:

我有以下代码:

import QtQuick 2.4
import QtQuick.Controls 1.4

ApplicationWindow
{
    id: myWindow2
    title: qsTr("test window")
    x: 500
    y: 200
    width: 800
    height: 600
    visible: true

    TextEdit
    {
        id: tEdit

        anchors.fill: parent

        MouseArea
        {
            anchors.fill: parent
            cursorShape: Qt.IBeamCursor
        }
    }
}

“MouseArea”以某种方式阻止了“tEdit”的工作。它确实改变了光标的形状。如何更改形状并让“tEdit”正常工作?

【问题讨论】:

    标签: qt qml qtquick2


    【解决方案1】:

    acceptedButtons 设置为Qt.NoButton 似乎有效:

    import QtQuick 2.4
    import QtQuick.Controls 1.4
    
    ApplicationWindow {
        id: myWindow2
        x: 500
        y: 200
        width: 800
        height: 600
        visible: true
    
        TextEdit {
            id: tEdit
            anchors.fill: parent
    
            MouseArea {
                anchors.fill: parent
                cursorShape: Qt.IBeamCursor
                acceptedButtons: Qt.NoButton
            }
        }
    }
    

    请注意,通过鼠标选择文本仍然有效,您只需将其设置为 true:

    selectByMouse: true
    

    【讨论】:

      猜你喜欢
      • 2021-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-16
      • 2011-08-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多