gpt4 book ai didi

c++ - Q3DScatter 没有出现在 QWidget 中

转载 作者:太空宇宙 更新时间:2023-11-04 12:41:09 27 4
gpt4 key购买 nike

我正在使用 QtDataVisualization 来设置单点的 3d 图。到目前为止,按照 Qt 示例中记录的方式使用相应的 Q3DScatter:

QGuiApplication app(argc, argv);

Q3DScatter scatter;
scatter.setFlags(scatter.flags() ^ Qt::FramelessWindowHint);

QScatter3DSeries *series = new QScatter3DSeries;
QScatterDataArray data;
data << QVector3D(0.5f, 0.5f, 0.5f) << QVector3D(-0.3f, -0.5f, -0.4f) << QVector3D(0.0f, -0.3f, 0.2f);
series->dataProxy()->addItems(data);
scatter.addSeries(series);

scatter.show();
return app.exec();

当我通过围绕该图包装 QWidget 对其进行修改时,该图未显示。该小部件显示为空(灰色)。

QGuiApplication app(argc, argv);

Q3DScatter scatter;
scatter.setFlags(scatter.flags() ^ Qt::FramelessWindowHint);

QWidget *container = QWidget::createWindowContainer(scatter);
QSize screenSize = scatter->screen()->size();
container->setMinimumSize(QSize(screenSize.width() / 2, screenSize.height() / 1.5));
container->setMaximumSize(screenSize);
container->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
container->setFocusPolicy(Qt::StrongFocus);

QScatter3DSeries *series = new QScatter3DSeries;
QScatterDataArray data;
data << QVector3D(0.5f, 0.5f, 0.5f) << QVector3D(-0.3f, -0.5f, -0.4f) << QVector3D(0.0f, -0.3f, 0.2f);
series->dataProxy()->addItems(data);
scatter.addSeries(series);

container->show();
return app.exec();

我的代码有问题吗?

最佳答案

来自 QGuiApplication ,“对于基于 QWidget 的 Qt 应用程序,请改用 QApplication,因为它提供了创建 QWidget 实例所需的一些功能”。然后可以进行以下操作:

    //    QGuiApplication app(argc, argv);
QApplication app(argc, argv);
QMainWindow w;

Q3DScatter scatter;
scatter.setFlags(scatter.flags() ^ Qt::FramelessWindowHint);

QWidget *container = QWidget::createWindowContainer(&scatter);
w.setCentralWidget(container);

QSize screenSize = scatter.screen()->size();
container->setMinimumSize(QSize(screenSize.width() / 2, screenSize.height() / 1.5));
container->setMaximumSize(screenSize);
container->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
container->setFocusPolicy(Qt::StrongFocus);

QScatter3DSeries *series = new QScatter3DSeries;
QScatterDataArray data;
data << QVector3D(0.5f, 0.5f, 0.5f) << QVector3D(-0.3f, -0.5f, -0.4f) << QVector3D(0.0f, -0.3f, 0.2f);
series->dataProxy()->addItems(data);
scatter.addSeries(series);

// container->show();
w.show();

return app.exec();

关于c++ - Q3DScatter 没有出现在 QWidget 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54197961/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com