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
ИМ
Игорь МаксимовNov. 22, 2024, 11:51 a.m.
Django - Tutorial 017. Customize the login page to Django Добрый вечер Евгений! Я сделал себе авторизацию аналогичную вашей, все работает, кроме возврата к предидущей странице. Редеректит всегда на главную, хотя в логах сервера вижу запросы на правильн…
Evgenii Legotckoi
Evgenii LegotckoiOct. 31, 2024, 2:37 p.m.
Django - Lesson 064. How to write a Python Markdown extension Добрый день. Да, можно. Либо через такие же плагины, либо с постобработкой через python библиотеку Beautiful Soup
A
ALO1ZEOct. 19, 2024, 8:19 a.m.
Fb3 file reader on Qt Creator Подскажите как это запустить? Я не шарю в программировании и кодинге. Скачал и установаил Qt, но куча ошибок выдается и не запустить. А очень надо fb3 переконвертировать в html
ИМ
Игорь МаксимовOct. 5, 2024, 7:51 a.m.
Django - Lesson 064. How to write a Python Markdown extension Приветствую Евгений! У меня вопрос. Можно ли вставлять свои классы в разметку редактора markdown? Допустим имея стандартную разметку: <ul> <li></li> <li></l…
d
dblas5July 5, 2024, 11:02 a.m.
QML - Lesson 016. SQLite database and the working with it in QML Qt Здравствуйте, возникает такая проблема (я новичок): ApplicationWindow неизвестный элемент. (М300) для TextField и Button аналогично. Могу предположить, что из-за более новой верси…
Now discuss on the forum
m
moogoNov. 22, 2024, 7:17 a.m.
Mosquito Spray System Effective Mosquito Systems for Backyard | Eco-Friendly Misting Control Device & Repellent Spray - Moogo ; Upgrade your backyard with our mosquito-repellent device! Our misters conce…
Evgenii Legotckoi
Evgenii LegotckoiJune 24, 2024, 3:11 p.m.
добавить qlineseries в функции Я тут. Работы оень много. Отправил его в бан.
t
tonypeachey1Nov. 15, 2024, 6:04 a.m.
google domain [url=https://google.com/]domain[/url] domain [http://www.example.com link title]
NSProject
NSProjectJune 4, 2022, 3:49 a.m.
Всё ещё разбираюсь с кешем. В следствии прочтения данной статьи. Я принял для себя решение сделать кеширование свойств менеджера модели LikeDislike. И так как установка evileg_core для меня не была возможна, ибо он писался…

Follow us in social networks