0

Does somebody know how to make QChart look like on the image below?

I have created bar QBarChart and set its background color and color of the bar and removed axis numbers, but I don't know how to set title of the chart to look like this.

How to make the background of the title to have different color and to take same width as the QChart?

enter image description here

4

1 回答 1

0

我按照 Spinkoo 的建议做了。

在 MainWindow 构造函数中创建了 QLabel 并创建了用于将 QLabel 定位在 QChart 上的函数。该函数必须在 MainWindow 的构造函数之后调用,因为这样所有小部件和布局的大小和位置都是已知的。该函数在 MainWindow 的构造函数之后以及每次发生 Resize 事件时调用。

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 类,该类的外观与问题中的图表一样。所以,如果有人知道如何做到这一点,我会很感激分享。

于 2019-02-21T07:56:48.623 回答