【发布时间】:2016-10-26 21:09:27
【问题描述】:
我在 Scrollview 内有一个 MouseArea 在 Rectangle 内。我实现了一个缩放功能,可以在按下 ctrl 并滚动鼠标滚轮时放大/缩小。但是,它仅在ScrollView 一直位于顶部时才会放大,并且仅当ScrollView 一直位于底部时才会缩小。还有一些额外的逻辑来处理文件的外部拖放。只要TextEdit 中的文本足够大以获取ScrollView,就应该能够复制该问题。显然这是以前的错误,但我无法使其正常工作。我还尝试了以下链接中的解决方案:
QtQuick2: Handle onWheel event inside of a ScrollView
Rectangle {
id: palGenRectangle
Layout.minimumWidth: 50
property string display
//width:800
color: "white"
ScrollView {
id: palGenTextScrollView
anchors.fill: parent
MouseArea {
id: mouseArea
anchors.fill: parent
onWheel: {
if (wheel.modifiers & Qt.ControlModifier){
if (wheel.angleDelta.y > 0)
{
mainTextEdit.font.pixelSize++
console.log("+++++")
}
else
{
mainTextEdit.font.pixelSize--
console.log("-----")
}
}
else{
wheel.accepted=true
}
}
}
DropArea {
anchors.fill: parent
onEntered: {
palGenRectangle.color = "light blue"
}
onExited: {
palGenRectangle.color = "white"
}
onDropped: {
palGenRectangle.color = "white"
if (drop.hasText) {
if (drop.proposedAction == Qt.MoveAction || drop.proposedAction == Qt.CopyAction) {
fileio.setPalFileTextFromFile(drop.text)
fileio.mainTextEdit = mainTextEdit.textDocument
drop.acceptProposedAction()
}
}
}
}
Item {
id: draggable
anchors.fill: parent
Drag.active: mouseArea.drag.active
Drag.hotSpot.x: 0
Drag.hotSpot.y: 0
Drag.mimeData: { "text/plain": palGenRectangle.display }
Drag.dragType: Drag.Automatic
Drag.onDragStarted:
Drag.onDragFinished: {
if (dropAction == Qt.MoveAction) {
item.display = ""
}
}
}
TextEdit {
id: mainTextEdit
text: fileio.palFileText
wrapMode: TextEdit.Wrap
selectByMouse: true
onTextChanged: {
if (fileio.palFileText !== mainTextEdit.text)
fileio.textIsModified = true
else
fileio.textIsModified = false
}
}
}
【问题讨论】: