简体   繁体   English

如何在Qt的主窗口中完全显示jpeg图像

[英]how to display a jpeg image completely on main window in Qt

I have a gui application which accepts some commands from other application. 我有一个gui应用程序,它接受来自其他应用程序的一些命令。

There is a scenario where gui will receive a command to display some jpeg image completely on the main window, overshadowing all of gui on the window and then again I need to clear that image with another command. 在某些情况下,gui会收到一个命令,以在主窗口上完全显示一些jpeg图像,从而使该窗口上的所有gui都黯然失色,然后我再次需要使用另一个命令来清除该图像。

For this I will need to call a member function and need to do all this stuff there, but I don't know how can I display the image on main window from there. 为此,我将需要调用成员函数并在其中执行所有这些操作,但是我不知道如何从那里在主窗口上显示图像。

can anybody please help me with that. 有人可以帮我吗

I have tried the below code. 我尝试了下面的代码。

void App::display_testpattern(QString path){

QPixmap imageObject(path);
imageObject = imageObject.scaled(300,300,Qt::IgnoreAspectRatio);
mylabel=new QLabel("",backup);
mylabel->setGeometry(QRect(0,0,300,300));
mylabel->setPixmap(imageObject);

} }

and this works for me only when I call it from constructor. 仅当我从构造函数调用它时,此方法才对我有用。 But I need to call it from some other slot and it does not work for me. 但是我需要从其他位置调用它,它对我不起作用。 any suggestions on this 关于这个的任何建议

Yes we can do the way I mentioned at the end of my question. 是的,我们可以按照我在问题末尾提到的方式进行操作。 The problem was allocation of QLabel. 问题是QLabel的分配。 we need to allocate QLabel in constructor and this will work fine. 我们需要在构造函数中分配QLabel,它将正常工作。

Thanks 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM