Flickable / TextEdit中的MouseArea不使用propagateComposedEvents传递鼠标事件

时间:2014-04-02 00:14:20

标签: qt qml

import QtQuick 2.2
import QtQuick.Window 2.1
import QtQuick.Controls 1.1

ApplicationWindow {
    flags: Qt.FramelessWindowHint
    width: 500
    height: 500
    x: (Screen.width - width) / 2
    y: (Screen.height - height) / 2
    color: "black"
    opacity: 0.8

    Flickable {
        anchors.fill: parent
        contentWidth: html.paintedWidth
        contentHeight: html.paintedHeight
        boundsBehavior: Flickable.StopAtBounds
        TextEdit {
            id: html
            objectName: "html"
            anchors.fill: parent
            textFormat: TextEdit.RichText
            focus: true
            Keys.onEscapePressed: Qt.quit()
            font.family: "Droid Sans Mono"
            font.pointSize: 11
            selectByMouse: true
            readOnly: true
            MouseArea {
                anchors.fill: parent
                propagateComposedEvents: true
                onClicked: {
                    console.log("clicked")
                    mouse.accepted = false
                }
            }
        }
    }
}

我无法点击“点击”...好像propagateComposedEventsmouse.accepted似乎没有按预期工作。

我正在使用Qt 5.3 Beta。

1 个答案:

答案 0 :(得分:0)

contentWidth /高度错误,

import QtQuick 2.2
import QtQuick.Window 2.1
import QtQuick.Controls 1.1

ApplicationWindow {
    flags: Qt.FramelessWindowHint
    width: 500
    height: 500
    x: (Screen.width - width) / 2
    y: (Screen.height - height) / 2
    //color: "black"
    opacity: 0.8
    visible: true

    Flickable {
        anchors.fill: parent
        //contentWidth: html.paintedWidth
        //contentHeight: html.paintedHeight
        boundsBehavior: Flickable.StopAtBounds
        TextEdit {
            id: html
            objectName: "html"
            anchors.fill: parent
            textFormat: TextEdit.RichText
            focus: true
            Keys.onEscapePressed: Qt.quit()
            font.family: "Droid Sans Mono"
            font.pointSize: 11
            selectByMouse: true
            readOnly: true
            text: "hello world"
            MouseArea {
                anchors.fill: parent
                propagateComposedEvents: true
                onClicked: {
                    console.log("clicked")
                    mouse.accepted = false
                }
            }
        }
    }
}