Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

save a qchart with QMessageBox



  • hello I have a chart and I would like to make a QMessageBox for the choice if we want to save it or not how can i do it please
    to save the chart with the date it is with :
    QString fileim =QDateTime::currentDateTime().toString(QString("'%1/graphe_'yyyy_MM_dd'_'hh_mm_ss'.png").arg(dossier));
    QPixmap p = chartView->grab();
    p.save(fileim);

    chart code :
    QChart *chart = new QChart(); // Pointer sur charte
    chart->legend()->hide();
    chart->addSeries(series);
    chart->createDefaultAxes();
    chart->axes(Qt::Vertical).first()->setRange(-3, 3);
    chart->axes(Qt::Horizontal).first()->setRange(-10, 10);
    chart->setBackgroundBrush(QBrush(Qt::black));
    QChartView *chartView = new QChartView(chart);
    chartView->setRenderHint(QPainter::Antialiasing);
    QMainWindow window;
    window.setCentralWidget(chartView);
    window.resize(500, 500);
    window.show();



  • @lindaah said in save a qchart with QMessageBox:

    I would like to make a QMessageBox for the choice if we want to save it or not how can i do it please

    Display the message box to ask the question, e.g. via https://doc.qt.io/qt-5/qmessagebox.html#question. Then save or not according to response.

    Or use QFileDialog to allow the user to pick a filename/path to save to, https://doc.qt.io/qt-5/qfiledialog.html#getSaveFileName. But not if you are wanting to control the filename/path, as per the filename code you are using.


Log in to reply