关于Qt Charts 中的柱状图界面的全面知识点

enum QAbstractBarSeries::LabelsPosition

This enum value describes the position of the data value labels:

 

Constant

Value

Description

QAbstractBarSeries::LabelsCenter

0

Label is located in the center of the bar.

QAbstractBarSeries::LabelsInsideEnd

1

Label is located inside the bar at the top.

QAbstractBarSeries::LabelsInsideBase

2

Label is located inside the bar at the bottom.

QAbstractBarSeries::LabelsOutsideEnd

3

Label is located outside the bar at the top.

 

QAbstractAxis Class


alignment : const Qt::Alignment
color : QColor
gridLineColor : QColor
gridLinePen : QPen
gridVisible : bool

labelsAngle : int
labelsBrush : QBrush
labelsColor : QColor
labelsFont : QFont
labelsVisible : bool
linePen : QPen
lineVisible : bool
minorGridLineColor : QColor
minorGridLinePen : QPen
minorGridVisible : bool
orientation : const Qt::Orientation
reverse : bool
shadesBorderColor : QColor
shadesBrush : QBrush
shadesColor : QColor
shadesPen : QPen
shadesVisible : bool
titleBrush : QBrush
titleFont : QFont
titleText : QString
titleVisible : bool
visible : bool

1 property inherited from QObject 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,以下是一个用Qt绘制柱状图的示例代码: ```cpp #include <QApplication> #include <QWidget> #include <QPainter> class BarChart : public QWidget { public: BarChart(QWidget *parent = nullptr) : QWidget(parent) { setFixedSize(400, 300); } protected: void paintEvent(QPaintEvent *) override { QPainter painter(this); const int margin = 30; const int barWidth = (width() - 2 * margin) / m_values.size() - 10; const int maxValue = *std::max_element(m_values.begin(), m_values.end()); const int maxHeight = height() - 2 * margin; painter.setPen(Qt::black); painter.drawLine(margin, margin, margin, height() - margin); // y-axis painter.drawLine(margin, height() - margin, width() - margin, height() - margin); // x-axis for (int i = 0; i < m_values.size(); ++i) { int barHeight = static_cast<int>(m_values[i] * maxHeight / maxValue); int x = margin + i * (barWidth + 10); int y = height() - margin - barHeight; QRect rect(x, y, barWidth, barHeight); painter.fillRect(rect, Qt::blue); painter.drawRect(rect); } } public: void setValues(const std::vector<int>& values) { m_values = values; update(); } private: std::vector<int> m_values; }; int main(int argc, char *argv[]) { QApplication a(argc, argv); BarChart chart; chart.setValues({ 10, 20, 30, 40, 50 }); chart.show(); return a.exec(); } ``` 在示例代码,我们继承了QWidget类,并重写了paintEvent函数进行绘图。我们使用QPainter类来绘制柱状图。在paintEvent函数,我们首先绘制了x轴和y轴。然后,我们根据数据值绘制柱状图。为了让柱状图看起来更好,我们给每个柱子留出了一定的空白。最后,我们通过调用update函数来刷新界面,使柱状图显示出来。 你可以根据需要修改该示例代码以满足你的需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值