Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How do I get rid of the margin around a ChartView?
Forum Updated to NodeBB v4.3 + New Features

How do I get rid of the margin around a ChartView?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
6 Posts 4 Posters 2.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    igor_stravinsky
    wrote on last edited by
    #1

    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"
    }
    

    0_1519158063349_Screen Shot 2018-02-20 at 12.17.18 PM.png

    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.

    1 Reply Last reply
    0
    • I Offline
      I Offline
      igor_stravinsky
      wrote on last edited by
      #2

      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?

      1 Reply Last reply
      0
      • 6thC6 Offline
        6thC6 Offline
        6thC
        wrote on last edited by
        #3

        I've had support already raise this as: https://bugreports.qt.io/browse/QTBUG-66150

        I 1 Reply Last reply
        0
        • 6thC6 6thC

          I've had support already raise this as: https://bugreports.qt.io/browse/QTBUG-66150

          I Offline
          I Offline
          igor_stravinsky
          wrote on last edited by
          #4

          @6thC

          Thanks for submitting the bug!

          1 Reply Last reply
          0
          • Aleksey_KA Offline
            Aleksey_KA Offline
            Aleksey_K
            wrote on last edited by Aleksey_K
            #5

            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 another Rectangle 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.

            1 Reply Last reply
            0
            • J Offline
              J Offline
              Johan_R28
              wrote on last edited by
              #6

              Another trick is to add this following lines to ChartView

              anchors { fill: parent; margins: -15 }
              margins { right: 0; bottom: 0; left: 0; top: 0 }
              
              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved