How to capture current main window screen shot on button click, and set that captured image as modal window background in QT?
-
Hi Team, my requirement is capturing the current running main window screenshot when we clicked some button and opening that captured screenshot in the modal window or modal less window. In that modal window, I have to implement some Zoom in/out functionality. Is it possible to do that? Any suggestions, Thank you in advance.
-
-
Thank you Jsulm. I'll try this approach.
-
Hi Jsulm, I'm having some train tracks and text related signals. This code is worked for getting the screenshot and text on that. I'm not able to capture train tracks in that screenshot. any suggestion.
-
@NageswaRao What are "train tracks" and what code do you mean?
-
Sorry, Jsulm. I'll explain it. I'm having a desktop sample application of QT. After login to that application, we will land on to the dashboard. There we generally display one train track(i.e in the form of some railway train track using lines) and several stations information(in some text) in that dashboard. Now what I'm doing is, I added one button on the dashboard. after clicking that button I'm able to get a dialog box. In that dialog box, I'm getting a screenshot also with the following code.
auto active_window = qApp->activeWindow(); if (active_window) //could be null if your app doesn't have focus { QPixmap pixmap(active_window->size()); active_window->render(&pixmap); ui->label_pic->setPixmap(pixmap); }
In that screenshot, I'm not getting railway train tracks related lines.
Is there any suggestion to get that every thing when we capture the screen shot? -
@NageswaRao said in How to capture current main window screen shot on button click, and set that captured image as modal window background in QT?:
There we generally display one train track
How? Do you paint it in the paintEvent?
-
Hi Jsulm, thank you. OpenGL is used in sample application. so because of different layers on-screen, able to capture one layer. but with the below code, we achieved what I needed. thank you.
QRect crop_rect(500, 500, 250, 250); QImage desk = qApp->screens().at(0)->grabWindow( QDesktopWidget().winId(), crop_rect.left(), crop_rect.top(), crop_rect.width(), crop_rect.height()).toImage(); ui->label_pic->show(); ui->label_pic->setPixmap(QPixmap::fromImage(desk)); ui->label_pic->resize(200,200); ui->label_pic->setStyleSheet("border:5px solid grey");