How to set image fit to dialogbox in QT?
-
Hi Team,I've one doubt. That is, I have a button on the main window. after clicking that button I'm able to open a dialog box and able to set an image using lable in that dialog box. What I need is, how to set that lable image fit to that dialog box. Is it possible? Thank you.
-
@NageswaRao said in How to set image fit to dialogbox in QT?:
how to set that lable image fit to that dialog box
Do you have a layout in your dialog box?
-
@jsulm I'm not having any layout in that dialog box. I'm just having a label. In that label I'm displaying an image using the following code.
QPixmap qpm("C:/Users/user/Desktop/essentials/demo2/sample_landscape_castle_szuarin.PNG");
ui->label_pic->setPixmap(qpm.scaled(300,300,Qt::KeepAspectRatio)); -
@NageswaRao
You need a layout to get sizing etc. to work correctly. Try adding, say, aQVBoxLayout
(dialog -> layout -> label) and then see how it is? -
@JonB
I added QVBoxLayout, like below.
QWidget *window = new QWidget;
QPushButton *button1 = new QPushButton("One");QVBoxLayout *layout = new QVBoxLayout; layout->addWidget(button1); window->setLayout(layout); window->show();
The above code is working fine. It's opening one dialog box and in that it's having one button. My problem is how to add the screenshot to the label which is inside to layout.
auto active_window = qApp->activeWindow();
if (active_window)
{
QPixmap pixmap(active_window->size());
active_window->render(&pixmap);
ui->label_pic->setPixmap(pixmap);
} -
@NageswaRao said in How to set image fit to dialogbox in QT?:
My problem is how to add the screenshot to the label which is inside to layout.
And what's wrong with the code you just showed? Looks OK to me.....
-
@NageswaRao said in How to set image fit to dialogbox in QT?:
My problem is how to add the screenshot to the label which is inside to layout.
Your button
One
should take / trigger the screenshot?Use the
QPushButton::clicked
signal to call a function with your code, that takes the screenshot.