Unsolved Taking screenshot of the dialog
-
Hello, I am trying to take screenshot of QT dialog. For that I am using these lines:
void secDialog::on_pushButton_clicked() { ui->status->setText(""); QPixmap originalPixmap; // clear image for low memory situations QRect crop_rect(60, 230, 841, 170); QImage qt_screenshot = qApp->screens().at(0)->grabWindow(QDesktopWidget().winId(),crop_rect.left(),crop_rect.top(),crop_rect.width(),crop_rect.height()).toImage(); ui->status->setText("Screenshot is taken..."); }
I have 2 related questions:
- That does not capture any image. Is there any other way that I can use?
- I don't want user to press the button multiple times so I want to implement delay. But sleep() function looks like stopping all other operations. Is there a way I can achieve it by not using timers?
P.S: I am really new to both QT and C++, sorry if these seem like easy questions. Thanks beforehand.
-
@GunkutA You can do it way easier: https://stackoverflow.com/questions/10381854/how-to-create-screenshot-of-qwidget
Use https://doc.qt.io/qt-5/qwidget.html#renderQPixmap pixmap(widget->size()); widget->render(&pixmap);
-
@jsulm said in Taking screenshot of the dialog:
QPixmap pixmap(widget->size());
widget->render(&pixmap);Thanks for the reply, as I said I am beginner. Well I could not get what is widget in here represents to. I need to take the screenshot of the some part of the dialog which consists of multiple windgets ( I guess.). What should I put instead of widget? Also is there a way to choose the destination of the image will be saved?
-
@GunkutA Replace widget with your dialog (a dialog is a widget also)
-
@jsulm Thank you