有人知道如何在下面的图片上使QChart看起来像吗?
我已经创建了条形图( bar QBarChart ),并设置了它的背景色和条形图的颜色,并删除了轴数,但我不知道如何设置图表的标题,使其看起来像这样。
如何使标题的背景有不同的颜色和相同的宽度与QChart?

发布于 2019-02-21 07:56:48
我照Spinkoo的建议做了。
在QLabel构造函数中创建QLabel,并创建用于将QLabel定位于QChart的函数。必须在MainWindow的构造函数之后调用该函数,因为这样就知道了小部件和布局的所有大小和位置。该函数在MainWindow的构造函数之后调用,每次发生调整大小事件时都调用该函数。
void MainWindow::positionLabel()
{
// ui->widget inside which is QChart
// ui->verticalLayout inside which is ui->widget
QPoint pos = ui->widget->pos() + ui->verticalLayout->geometry().topLeft();
// m_title pointer to QLabel which is created inside constructor
m_title->setGeometry(pos.x() + 10, pos.y() + 20, ui->widget->width() - 20, CHART_TITLE_SIZE * 2.2);
this->repaint();
return;
}这是一个很好的解决方案,也许应该有一种方法来创建自定义的QChart类,它看起来就像问题中的图表。所以,如果有人知道怎么做的话,我会很感激分享的。
https://stackoverflow.com/questions/54782220
复制相似问题