QChartView margins
-
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 tabm_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
My question is, can I make the QChart occupy the complete QChartView? I don't need these margings.
Thanks
-
Hi
Make sure
layoutCart
has setContentsMargins(0,0,0,0); -
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
With m_cartView->setContentsMargins(20, 20, 20, 20);
With m_cartGraph->setContentsMargins(20, 20, 20, 20);
I also tried
m_cartGraph->setContentsMargins(-11, -11, -11, -11); which gives the following
I think this is not the correct way to do it.
-
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.
-
Hi
Super.
So its a QScrollArea.
I tried to doauto 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.