How do I get rid of the margin around a ChartView?
-
QtQuickControls 2 app using 5.10...
I've got a ChartView inside a Rectangle, and I'd like the ChartView to fill the Rectangle, but there's a mysterious border around the ChartView...
Rectangle{ color:"yellow" anchors.fill:parent ChartView { id:chartView title: "My Graph" titleColor: Qt.rgba(.5,.5,.5,1) titleFont.pointSize:20 margins.top:0 legend.visible:false anchors.fill: parent antialiasing: true backgroundColor: "black" }
What's causing this? How can I get the black background of the chart to fill the yellow rectangle?
It's clearly an issue with ChartView, as placing another rectangle inside the yellow rectangle, and asking it to fill creates a new rectangle that covers the yellow completely, as expected.
-
It looks like the work-around that others have used is to set anchorMargins to -15, which works.
It would be nice to find a more beautiful solution. Why should a chart behave any different than a Rectangle with regards to positioning?
-
I've had support already raise this as: https://bugreports.qt.io/browse/QTBUG-66150
-
I had same bug with modal dialog: white border around the dialog and somehow solved it with:
contentItem: Rectangle { anchors.fill: parent color: "black" border.width: 1 ... }
Here I solved it by settings margins to zero and wrapping
ChartView
into anotherRectangle
with same background color as setting negative fixed margins is not quite correct as necessary values could be different:Item { Rectangle { color: "black" anchors.fill: parent } ChartView { id: chart anchors.fill: parent antialiasing: true margins { top: 0; bottom: 0; left: 0; right: 0 } // plotArea: Qt.rect(0, 0, width, height) backgroundColor: "black" backgroundRoundness: 0 legend.visible: false ... } }
Commented out
plotArea: Qt.rect(0, 0, width, height)
might solve the issue as well but it don't: as axis and axis labels disappear in this case for some reason.