Qt5.8 QML 为啥只读的 Controls2.TextArea 有 ibeam 光标?

Posted

技术标签:

【中文标题】Qt5.8 QML 为啥只读的 Controls2.TextArea 有 ibeam 光标?【英文标题】:Qt5.8 QML Why does a read-only Controls2.TextArea have the ibeam cursor?Qt5.8 QML 为什么只读的 Controls2.TextArea 有 ibeam 光标? 【发布时间】:2017-02-01 21:23:40 【问题描述】:

Qt5.7 这个例子给出了“指针”光标,但是 Qt5.8,我得到了“ibeam”光标(就像我要插入一样)。

import QtQuick 2.7
import QtQuick.Controls 2

ApplicationWindow

    width: 1024
    height: 800

    visible: true

    Flickable 
    
        anchors.fill: parent
        flickableDirection: Flickable.VerticalFlick

        TextArea.flickable: TextArea
        
            font.pixelSize: 25
            text: "hello world"
            readOnly: true
        
    

这是有意更改吗,如果是,我如何显示只读 TextArea 的指针光标?

谢谢。

更新 #1:

添加一个虚拟MouseArea 似乎可以修复它。我不知道为什么/

像这样:

 Flickable 
    
        anchors.fill: parent
        flickableDirection: Flickable.VerticalFlick

        TextArea.flickable: TextArea
        
            font.pixelSize: 25
            text: "hello world"
            readOnly: true

            MouseArea 
            
                anchors.fill: parent
                enabled: false
            
        
    

【问题讨论】:

听起来像是一个应该很容易修复的疏忽。请在 bugreports.qt.io 报告。 @jpnurmi 谢谢。我找到了一种解决方法,但我不明白它为什么有效。无论如何... 可能是因为MouseArea 的默认cursorShapeQt.ArrowCursor:doc.qt.io/qt-5/qml-qtquick-mousearea.html#cursorShape-prop。顺便说一句,你能回答你的问题并接受它,这样我们就知道它已经解决了吗? :) 该错误已在 Qt 5.8.1 和/或 5.9.0 中修复:codereview.qt-project.org/#/c/185002 感谢您的错误修复!我同时发布了这个效果的答案和我的解决方法。 【参考方案1】:

在 Mitch 和 Jpnurmi 的 cmets 之后,显然这是一个现已修复的错误。太好了!

与此同时,我的解决方法是一个虚拟的MouseArea

 TextArea.flickable: TextArea
        
            font.pixelSize: 25
            text: "hello world"
            readOnly: true

            MouseArea 
            
                anchors.fill: parent
                enabled: false
            
        

【讨论】:

以上是关于Qt5.8 QML 为啥只读的 Controls2.TextArea 有 ibeam 光标?的主要内容,如果未能解决你的问题,请参考以下文章

QML QtQuick.Controls 2.2 Combobox 没有 selectByMouse;啥是替代方案?

可以为特定项目禁用 Qt 5.8 中的 QML 缓存吗?

对象属性循环 (QML)

QML登录界面

QML:调整复选框大小

Qml 样式按钮