我正在使用QtDataVisualization设置单点的3d图。 到目前为止,使用相应的Q3DScatter可以在Qt示例中记录的方式起作用:
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();
我的代码有问题吗?
答案 0 :(得分:0)
来自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();