首页 文章

MouseArea阻止编辑

提问于
浏览
1

我有以下代码:

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'工作?

1 回答

  • 2

    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
    

相关问题