QML ChartView: mapToValue не принимает точно?C++

Программы на C++. Форум разработчиков
Ответить
Anonymous
 QML ChartView: mapToValue не принимает точно?

Сообщение Anonymous »

У меня есть диаграмма, она имеет несколько случайных значений и работает хорошо.

Код: Выделить всё

import QtQuick 2.9
import QtQuick.Window 2.2
import QtCharts 2.0

Item {
visible: true
width: 640
height: 480

ChartView {
id: chartView
anchors.fill: parent
theme: ChartView.ChartThemeBrownSand
antialiasing: true

LineSeries {
id: liness
name: "LineSeries"
XYPoint {
x: 0
y: 0
}
XYPoint {
x: 1.1
y: 2.1
}
XYPoint {
x: 1.9
y: 3.3
}
XYPoint {
x: 2.1
y: 2.1
}
XYPoint {
x: 2.9
y: 4.9
}
XYPoint {
x: 3.4
y: 3.0
}
XYPoint {
x: 4.1
y: 3.3
}
}

LineSeries {
name: "xPositioner"
id: xPositionerX

style: Qt.DashLine
XYPoint {
x: 0
y: 2
}
XYPoint {
x: 4.1
y: 2
}
}

LineSeries {
name: "LineSeries"
id: positionery
style: Qt.DashLine
XYPoint {
x: 2
y: 0
}
XYPoint {
x: 2
y: 4.9
}
}

MouseArea {
anchors.fill: parent
cursorShape: Qt.CrossCursor
onDoubleClicked: chartView.zoomReset()

hoverEnabled: true
onPositionChanged: {
var p = Qt.point(mouse.x, mouse.y)
var cp = chartView.mapToValue(p, liness)

xPositionerX.replace(xPositionerX.at(1).x,
xPositionerX.at(1).y,
xPositionerX.at(1).x, cp.y)

xPositionerX.replace(xPositionerX.at(0).x,
xPositionerX.at(0).y,
xPositionerX.at(0).x, cp.y)

positionery.replace(positionery.at(1).x, positionery.at(1).y,
cp.x, positionery.at(1).y)

positionery.replace(positionery.at(0).x, positionery.at(0).y,
cp.x, positionery.at(0).y)

xMagView.x = mouseX - xMagView.width / 2
xMagText.text = cp.x

yMagView.y = mouseY - yMagView.height / 2
yMagText.text = cp.y

console.debug(mouseX, mouseY, cp.y)
}
}

Rectangle {
id: xMagView
width: 50
clip: true
height: 20
color: "#592e2e2e"
y: chartView.plotArea.y + chartView.plotArea.height
x: chartView.plotArea.x

Text {
clip: true
id: xMagText
anchors.fill: parent
wrapMode: Text.WrapAnywhere
horizontalAlignment: Text.AlignHCenter
}
}
Rectangle {
id: yMagView
width: 50
clip: true
height: 20
color: "#592e2e2e"
y: chartView.plotArea.y
x: chartView.plotArea.x - 50

Text {
clip: true
id: yMagText
anchors.fill: parent
wrapMode: Text.WrapAnywhere
horizontalAlignment: Text.AlignHCenter
}
}
}
}
В этом представлении диаграммы я показываю положение мыши, сопоставленное со значением на оси с помощью простого текста. но, похоже, оно имеет немного неточное значение, как показано на изображении:
Позиции mouseX и mouseY не совсем совпадают с Axis! :
пожалуйста, посмотрите на это изображение.
есть ли какие-то проблемы с mapToValue?
Спасибо за любые комментарии и помощь.
РЕДАКТИРОВАТЬ:
я немного изменил код, чтобы показать точную проблему.

Подробнее здесь: https://stackoverflow.com/questions/659 ... ry-exactly
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C++»