Screenshot with QT
-
Im using the code below for taking screenshot of my charts.
But i dont want to open a file dialog.
I want to save them with a giving format. In every new picture it will save it the date and time.
I dont want to give a name.
How can i do it without file dialog?``` QRect crop_rect(int x, int y, int w, int h); QPixmap desk = qApp->screens().at(0)->grabWindow( QDesktopWidget().winId()); QString format = "jpg"; QString initialPath = tr("Screenshots") + tr("/Image.") + QDateTime::currentDateTime().toString("dd.MM.yyyy" "hh.mm.ss.") + format; QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"), initialPath, tr("%1 Files (*.%2);;All Files (*)") .arg(format.toUpper()) .arg(format)); if (!fileName.isEmpty()) desk.save(fileName, format.toLatin1().constData()); -
Im using the code below for taking screenshot of my charts.
But i dont want to open a file dialog.
I want to save them with a giving format. In every new picture it will save it the date and time.
I dont want to give a name.
How can i do it without file dialog?``` QRect crop_rect(int x, int y, int w, int h); QPixmap desk = qApp->screens().at(0)->grabWindow( QDesktopWidget().winId()); QString format = "jpg"; QString initialPath = tr("Screenshots") + tr("/Image.") + QDateTime::currentDateTime().toString("dd.MM.yyyy" "hh.mm.ss.") + format; QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"), initialPath, tr("%1 Files (*.%2);;All Files (*)") .arg(format.toUpper()) .arg(format)); if (!fileName.isEmpty()) desk.save(fileName, format.toLatin1().constData());@firsnur96 said in Screenshot with QT:
But i dont want to open a file dialog
Then don't open a dialog, what is the problem?
Construct the file name as you need and use it... -
@firsnur96 said in Screenshot with QT:
But i dont want to open a file dialog
Then don't open a dialog, what is the problem?
Construct the file name as you need and use it... -
@firsnur96 said in Screenshot with QT:
How can i do?
Are you asking me how to add a button?
Can you please explain what you want to do?
Should there be a button to select folder where user can store screen-shots?
What is the problem with that? Add a button, connect its clicked signal to a slot where you use https://doc.qt.io/qt-5/qfiledialog.html#getExistingDirectory to let the user select a folder, really nothing special... -
Im using the code below for taking screenshot of my charts.
But i dont want to open a file dialog.
I want to save them with a giving format. In every new picture it will save it the date and time.
I dont want to give a name.
How can i do it without file dialog?``` QRect crop_rect(int x, int y, int w, int h); QPixmap desk = qApp->screens().at(0)->grabWindow( QDesktopWidget().winId()); QString format = "jpg"; QString initialPath = tr("Screenshots") + tr("/Image.") + QDateTime::currentDateTime().toString("dd.MM.yyyy" "hh.mm.ss.") + format; QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"), initialPath, tr("%1 Files (*.%2);;All Files (*)") .arg(format.toUpper()) .arg(format)); if (!fileName.isEmpty()) desk.save(fileName, format.toLatin1().constData());@firsnur96 please don't double post