Updating a Q3DScatter by PushButton



  • Hello everybody,

    I'm new in Qt and I want to use a Q3DScatter for visualizing points.
    I embedded the Q3DScatter in a QWidget and the QWidget in a gridLayout.
    The code is shown below. It's just the Scatter without data.

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);

    Q3DScatter *graph = new Q3DScatter();

    QWidget *container = QWidget::createWindowContainer(graph);
    
    Q3DScatter *graph2 = new Q3DScatter();
    
    QWidget *container2 = QWidget::createWindowContainer(graph2);
    

    ui->gridLayout->addWidget(container);
    ui->gridLayout_2->addWidget(container2);
    }

    In the next step I want to use a PushButton for updating the points. The method looks like this:

    void MainWindow::on_pushButton_4_clicked()
    {
    scattermodifier *modifier = new scattermodifier(graph);

    scattermodifier *modifier_2 = new scattermodifier(graph2);

    }

    Basicly, the scattermodifier works but how can I use graph and graph2 from the MainWindow class?
    I guess it's a C++ topic but maybe anybody could give me a hint how to solve this problem :-)

    Thanks a lot.

    Kindly regards,

    Timo


  • Moderators

    @Timo_F I don't understand the problem: graph and graph2 are already created in MainWindow. The only thing you need to change is: make them class member:

    class MainWindow
    {
    private:
        Q3DScatter *graph;
        Q3DScatter *graph2;
    ...
    };
    
    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    
    graph = new Q3DScatter();
    
    QWidget *container = QWidget::createWindowContainer(graph);
    
    graph2 = new Q3DScatter();
    
    QWidget *container2 = QWidget::createWindowContainer(graph2);
    
    ui->gridLayout->addWidget(container);
    ui->gridLayout_2->addWidget(container2);
    }


  • Thanks, it works ^^.


Log in to reply