QPieSeries / QChartView Size
Marc A. Smith
In our project we've been using Qt 5.6 + QtCharts 2.1 (I think that was the version, commercial license). We recently upgraded to Qt 5.8 which now includes QtCharts (not a separate package). Our QtCharts widgets work, but I was surprised to see the size of the widgets significantly smaller than when using the previous version of Qt. Here is a sample of the code we're using:
lvm_series = new QPieSeries(this); lvm_series->append("Free", 1); lvm_series->append("Used", 1); lvm_series->slices().at(0)->setColor(LVM_FREE_COLOR); lvm_series->slices().at(1)->setColor(LVM_USED_COLOR); lvm_chart = new QChart(); lvm_chart->setTheme(SPACE_PIE_THEME); lvm_chart->addSeries(lvm_series); lvm_chart->setTitle("Volume Group Usage"); title_font = lvm_chart->titleFont(); title_font.setPointSize(title_font.pointSize() - 2); lvm_chart->setTitleFont(title_font); lvm_chart->setBackgroundVisible(false); lvm_chart->legend()->setAlignment(Qt::AlignBottom); legend_font = lvm_chart->legend()->font(); legend_font.setPointSize(legend_font.pointSize() - 3); lvm_chart->legend()->setFont(legend_font); lvm_chart->setMargins(QMargins(0, 0, 0, 0)); lvm_chart_view = new QChartView(lvm_chart, this); lvm_chart_view->setRenderHint(QPainter::Antialiasing); lvm_chart_view->setMinimumWidth(250); ui->lvm_summ_group_box->layout()->addWidget(lvm_chart_view);
I haven't started experimenting to see what's causing the size to be different then what we got with the previous version of Qt (well, 5.6 was what we were using). Was hoping it might be a quick fix, or simple solution that someone else already came across?
Marc A. Smith
I figured it out... adding "lvm_chart_view->setMinimumHeight(200);" appears to have restored the size to about what it was originally. And a correction on versions, we're using 5.9 now (not 5.8). Not sure what default sizing behavior changed between versions, but setting the height in the not a big deal.