【发布时间】:2021-02-20 01:39:13
【问题描述】:
有人知道如何去掉这个间距吗?
下面的那些行减少了它们,但没有完全删除。
margins.top: 0
margins.bottom: 0
margins.left: 0
margins.right: 0
更新 我添加了一些代码。可能这有助于确定我的问题。最初箭头所在的那些空白区域用于图例和刻度值。我想不改变源代码我什么都做不了。
ScopeView.qml
import QtQuick 2.0
import QtCharts 2.1
ChartView {
id: chartView
animationOptions: ChartView.NoAnimation
theme: ChartView.ChartThemeQt
legend.visible: false
margins.top: 0
margins.bottom: 0
margins.left: 0
margins.right: 0
backgroundRoundness: 0
property bool openGL: true
onOpenGLChanged: {
series("signal 1").useOpenGL = openGL;
}
ValueAxis {
id: axisY1
min: -1
max: 4
labelsVisible: false
tickCount: 3
color: "transparent"
}
ValueAxis {
id: axisX
min: 0
max: 1024
labelsVisible: false
tickCount: 4
color: "transparent"
}
LineSeries {
id: lineSeries1
name: "signal 1"
axisX: axisX
axisY: axisY1
useOpenGL: chartView.openGL
color: "#44D77B"
}
Timer {
id: refreshTimer
interval: 1 / 60 * 1000 // 60 Hz
running: true
repeat: true
onTriggered: {
dataSource.update(chartView.series(0));
}
}
function changeSeriesType(type) {
chartView.removeAllSeries();
// Create two new series of the correct type. Axis x is the same for both of the series,
// but the series have their own y-axes to make it possible to control the y-offset
// of the "signal sources".
if (type == "line") {
var series1 = chartView.createSeries(ChartView.SeriesTypeLine, "signal 1",
axisX, axisY1);
series1.useOpenGL = chartView.openGL
} else {
var series1 = chartView.createSeries(ChartView.SeriesTypeScatter, "signal 1",
axisX, axisY1);
series1.markerSize = 2;
series1.borderColor = "transparent";
series1.useOpenGL = chartView.openGL
}
}
function createAxis(min, max) {
// The following creates a ValueAxis object that can be then set as a x or y axis for a series
return Qt.createQmlObject("import QtQuick 2.0; import QtCharts 2.0; ValueAxis { min: "
+ min + "; max: " + max + " }", chartView);
}
function setAnimations(enabled) {
if (enabled)
chartView.animationOptions = ChartView.SeriesAnimations;
else
chartView.animationOptions = ChartView.NoAnimation;
}
function changeRefreshRate(rate) {
refreshTimer.interval = 1 / Number(rate) * 1000;
}
}
更新 II
诀窍是使用clip 并将chartView into 放在一个矩形中。
Rectangle {
id: canvas
anchors{
left: parent.left
right: parent.right
top: parent.top
}
height: 250
color: "#FFFFFF"
z: propText.z - 1
clip: true
Rectangle {
width: parent.width
height: 40
z: 1
color: "#FFFFFF"
}
GraphView{ //ChartView
id: graphView
isTimerRunnig: isRunning
channelId: channelId
}
}
和ChartView aka GraphView
ChartView {
id: chartView
property alias channelId: dataSource.channelId
property alias isTimerRunnig: refreshTimer.running
property bool openGL: true
antialiasing: !openGL
legend.visible: false
margins.top: 0
margins.bottom: 0
margins.left: 0
margins.right: 0
x: -70
y: 20
width: 360
height: 262
backgroundRoundness: 0
onOpenGLChanged: {
series("signal 1").useOpenGL = openGL;
}
DataSource {
id: dataSource
channelId: channelId
isPaused: !isTimerRunnig
onIsPausedChanged: {
if(isPaused){
lineSeries1.clear()
}
}
}
ValueAxis {
id: axisY
//gridVisible: false
labelsVisible: false
tickCount: 3
color: "transparent"
}
ValueAxis {
id: axisX
min: 0
max: 100
//gridVisible: false
labelsVisible: false
tickCount: 4
color: "transparent"
}
LineSeries {
id: lineSeries1
name: "signal 1"
axisX: axisX
axisY: axisY
useOpenGL: chartView.openGL
color: "#44D77B"
width: 2
}
Timer {
id: refreshTimer
interval: 1 / 25 * 1000 // 25 Hz
running: isTimerRunnig
repeat: true
onTriggered: {
dataSource.updateFromQML(chartView.series(0), chartView.axisY(chartView.series(0)))
//dataSource.printChannelId()
}
}
【问题讨论】:
-
你的 .qml 代码在哪里?
-
@Nulik 请检查我的更新。
-
同时在 Qt 的 bug-tracker 上有一个相关的 feature request。任何有兴趣在 Qt 方面“修复”此问题的人,请为该功能投票。
-
问题与轴有关。如果我将两个轴都设置为不可见,则边距消失。这是第一步,尽管不是解决方案。