2016-09-05 62 views
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 
     } 
    } 
} 

不知何故,“鼠标区域”防止“TEDIT”工作。它确实会改变光标的形状。我怎么能改变形状和'tEdit'的工作?

回答

2

设置acceptedButtonsQt.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