如何在Q3DSurface上设置轴标签?

时间:2019-09-26 23:21:08

标签: qt opengl 3d qt5 qwidget

我尝试通过以下操作在Q3DSurface上设置轴标签:

#include "mainwindow.h"

#include <Q3DSurface>

using namespace QtDataVisualization;

MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
{
    Q3DSurface *graph = new Q3DSurface;
    QWidget *widget = QWidget::createWindowContainer(graph);
    setCentralWidget(widget);
    graph->axisX()->setLabels(QStringList{"a", "b", "c"});
}

MainWindow::~MainWindow() {}

但是标签没有显示,如何显示它们的提示?

enter image description here

2 个答案:

答案 0 :(得分:0)

为QValue3DAxis设置此属性不会执行任何操作,因为它会自动生成标签。

https://doc.qt.io/qt-5/qabstract3daxis.html#labels-prop

答案 1 :(得分:0)

我认为您想设置轴标题,而不是标签。默认隐藏的标题

#include "mainwindow.h"

#include <Q3DSurface>

using namespace QtDataVisualization;

MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
{
    Q3DSurface *graph = new Q3DSurface;
    QWidget *widget = QWidget::createWindowContainer(graph);
    setCentralWidget(widget);

    m_graph->axisX()->setTitle(QStringLiteral("a"));
    m_graph->axisY()->setTitle(QStringLiteral("b"));
    m_graph->axisZ()->setTitle(QStringLiteral("c"));

    m_graph->axisX()->setTitleVisible(true);
    m_graph->axisY()->setTitleVisible(true);
    m_graph->axisZ()->setTitleVisible(true);
}

MainWindow::~MainWindow() {}