简体   繁体   中英

MouseArea prevents editing

I have the following code:

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
        }
    }
}

Somehow the 'MouseArea' prevents the 'tEdit' to work. It does change the shape of the cursor thou. How can I have the shape changed and the 'tEdit' working?

Setting acceptedButtons to Qt.NoButton seems to work:

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
        }
    }
}

Note that text selection via mouse still works, you just have to set it to true:

selectByMouse: true

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM