Evgenii Legotckoi
Evgenii LegotckoiDec. 23, 2015, 9:36 a.m.

Qt/C++ - Lesson 032. Saving picture in file from QCustomPlot

In a previous article on working with QCustomPlot was an example of the use of this library. But after the schedule is built, it may be necessary to make its preservation as a graphic file. QCustomPlot Library already provides methods necessary for this. All you need to do - is to create a file which will be saved and pass the path to the file in one of the methods to save the image.

Methods for saving images

saveRastered(const QString &fileName, int width, int height, double scale, const char *format, int quality)
saveJpg(const QString &fileName, int width, int height, double scale, int quality);
savePng(const QString &fileName, int width, int height, double scale, int quality);
saveBmp(const QString &fileName, int width, int height, double scale);
savePdf(const QString &fileName, bool noCosmeticPen, int width, int height, const QString &pdfCreator, const QString &pdfTitle);

saveRastered

It is a fundamental method for methods: saveJpg , savePng , saveBmp . So he called in all of these methods. Inside the method saveRastered QPixmap instance is created, through which the image is saved from QCustomPlot widget. For this method, you can specify the type of file to be saved. Then the remaining three methods simplify work and just write code, canceling the need to specify the file type.

savePdf

This method stands alone and does not use QPixmap , and runs through QPrinter . Although the use of logic in the minimum variant is similar to the rest of the methods.


Save image

Extend the code from the previous tutorial by adding the Save button in the slot where the preservation of the image will be in the file in the following path C:/example/customPlot.png.

In addition to the path to the file, you can specify image quality, its scale, and the parameters of the parties.

void MainWindow::on_pushButton_clicked()
{
    QString fileName("C:/example/customPlot.png");
    QFile file(fileName);

    if (!file.open(QIODevice::WriteOnly))
    {
        qDebug() << file.errorString();
    } else {
        wGraphic->savePng(fileName);
    }
}

We recommend hosting TIMEWEB
We recommend hosting TIMEWEB
Stable hosting, on which the social network EVILEG is located. For projects on Django we recommend VDS hosting.

Do you like it? Share on social networks!

Comments

Only authorized users can post comments.
Please, Log in or Sign up
AD

C ++ - Test 004. Pointers, Arrays and Loops

  • Result:50points,
  • Rating points-4
m

C ++ - Test 004. Pointers, Arrays and Loops

  • Result:80points,
  • Rating points4
m

C ++ - Test 004. Pointers, Arrays and Loops

  • Result:20points,
  • Rating points-10
Last comments
i
innorwallNov. 14, 2024, 12:05 p.m.
EVILEG-CORE. Using Google reCAPTCHA 2001; 98 29 34 priligy buy
i
innorwallNov. 14, 2024, noon
PyQt5 - Lesson 007. Works with QML QtQuick (Signals and slots) priligy 30mg Am J Obstet Gynecol 171 1488 505
i
innorwallNov. 14, 2024, 10:54 a.m.
Django - Tutorial 003. Model, Template, View on Django Hair follicles are believed to produce approximately 20 individual hair shafts over the life of the follicle as the follicle progresses through cycles of hair production, shedding ejection, invo…
i
innorwallNov. 14, 2024, 7:03 a.m.
How to make game using Qt - Lesson 3. Interaction with other objects what is priligy tablets What happens during the LASIK surgery process
i
innorwallNov. 14, 2024, 4:09 a.m.
Using variables declared in CMakeLists.txt inside C ++ files where can i buy priligy online safely Tom Platz How about things like we read about in the magazines like roid rage and does that really
Now discuss on the forum
i
innorwallNov. 14, 2024, 11:39 a.m.
добавить qlineseries в функции priligy amazon canada 93 GREB1 protein GREB1 AB011147 6
i
innorwallNov. 11, 2024, 6:55 p.m.
Всё ещё разбираюсь с кешем. priligy walgreens levitra dulcolax carbs The third ring was found to be made up of ultra relativistic electrons, which are also present in both the outer and inner rings
9
9AnonimOct. 25, 2024, 4:10 p.m.
Машина тьюринга // Начальное состояние 0 0, ,<,1 // Переход в состояние 1 при пустом символе 0,0,>,0 // Остаемся в состоянии 0, двигаясь вправо при встрече 0 0,1,>…

Follow us in social networks