Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QChartView margins
Forum Updated to NodeBB v4.3 + New Features

QChartView margins

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 2 Posters 1.3k Views 2 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.
  • B Offline
    B Offline
    Bert59
    wrote on last edited by
    #1

    Hi,

    I have a tabWidget with 2 tabs. In each tab I have added a vertical layout.
    I add programatically a QChartView in each layout.
    Here is the code for one tab

    m_cartView = new (QChartView);
    m_cartGraph = new (QChart);
    ui->layoutCart->addWidget(m_cartView);
    m_cartView->setChart(m_cartGraph);

    For testing I have added the following lines to show what is related to the QChartView and what is related to the QChart.

    m_cartGraph->setBackgroundBrush(Qt::yellow);
    m_cartView->setBackgroundBrush(Qt::red);

    I get the following result

    565dc1fe-0452-4e90-ac8f-c72fbb465f4e-image.png

    My question is, can I make the QChart occupy the complete QChartView? I don't need these margings.

    Thanks

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      Make sure
      layoutCart
      has setContentsMargins(0,0,0,0);

      1 Reply Last reply
      0
      • B Offline
        B Offline
        Bert59
        wrote on last edited by
        #3

        Hi,
        Thank you for your suggestion. Unfortunately it has no effect.
        I also tried
        m_cartGraph->setContentsMargins(0, 0, 0, 0);
        and
        m_cartView->setContentsMargins(0, 0, 0, 0);

        Then I tried the opposite to see if I can increase the margins.

        With ui->layoutCart->setContentsMargins(20, 20, 20, 20); Iget

        5f5d5fc9-e181-4899-b063-6cadee3e8960-image.png

        With m_cartView->setContentsMargins(20, 20, 20, 20);
        01ae49f6-d8c4-4d89-ad02-2b75662212d9-image.png

        With m_cartGraph->setContentsMargins(20, 20, 20, 20);
        c4934caa-9f23-4c2d-a773-2b68bfd823ca-image.png

        I also tried
        m_cartGraph->setContentsMargins(-11, -11, -11, -11); which gives the following
        81dbf0a4-75e2-4e48-b0ea-a94e445ad48e-image.png

        I think this is not the correct way to do it.

        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Ok so the margins is really from m_cartView.

          Try do
          m_cartView->dumpObjectTree();

          and see if it has an internal layout we could try fiddling with.

          1 Reply Last reply
          0
          • B Offline
            B Offline
            Bert59
            wrote on last edited by
            #5

            Here is what I get

            QtCharts::QChartView::
            QWidget::qt_scrollarea_hcontainer
            QScrollBar::
            QBoxLayout::
            QWidget::qt_scrollarea_vcontainer
            QScrollBar::
            QBoxLayout::
            QWidget::
            QGraphicsScene::
            QGraphicsSceneBspTreeIndex::

            mrjjM 1 Reply Last reply
            0
            • B Bert59

              Here is what I get

              QtCharts::QChartView::
              QWidget::qt_scrollarea_hcontainer
              QScrollBar::
              QBoxLayout::
              QWidget::qt_scrollarea_vcontainer
              QScrollBar::
              QBoxLayout::
              QWidget::
              QGraphicsScene::
              QGraphicsSceneBspTreeIndex::

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Hi
              Super.
              So its a QScrollArea.
              I tried to do

              auto list = chartView->findChildren<QBoxLayout *>();
                  for (QBoxLayout *lay : list) {
                      lay->setContentsMargins(0, 0, 0, 0);
                  }
              

              but it had no effect.
              So I don't know how to get rid of that border.

              1 Reply Last reply
              0
              • B Offline
                B Offline
                Bert59
                wrote on last edited by
                #7

                Thank for your time looking into this issue.

                For the time being to get rid of this border I have set Bakcground color of the QChartView to the same color as the background of the QChart.

                1 Reply Last reply
                1

                • Login

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