How to integrate a Q3DScatter graph into a Widget in a Main Window?



  • I'm trying to display a Q3DScatter graph in a Main Window designed with Qt Designer so I've added a widget to the main window but I don't know how to embed the graph object in this widget. I tried to create a widget "container" programmatically and embed the graph in it and then putting the widget in a QHBoxLayout (which has been added to the main window using Qt Designer) using the following code in my main window's constructor:

    ...
    Q3DScatter *graph = new Q3DScatter();
    QWidget *container = QWidget::createWindowContainer(graph);
    ui->horizontal_layout->addWidget(container, 1);
    

    But the window appears to be empty when executing. I'd really appreciate some help.



  • Code looks correct but you are not adding any series to the scatter... that's why it's empty

    Q3DScatter *graph = new Q3DScatter();
    
     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);
        graph->addSeries(series);
    QWidget *container = QWidget::createWindowContainer(graph,this);
    ui->horizontal_layout->addWidget(container);
    


  • This post is deleted!


  • @VRonin Thanks for answering! I've tried your code but it's still not showing the graph, here's the full code of my main window constructor:

    ResultsWindow::ResultsWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::ResultsWindow)
    {
    ui->setupUi(this);
    Q3DScatter *graph = new Q3DScatter();

     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);
     graph->addSeries(series);
    QWidget *container = QWidget::createWindowContainer(graph,this);
    ui->h_graph->addWidget(container);
    

    }

    The layout which is supposed to contain the graph appears empty.


Log in to reply