Unsolved not show image from resources in another window Qlabel
-
I have another window and Qlabel in this window. I need load image in Qlabel, but image not showing.
QT 5.15.2.QPixmap pm;
bool load_result = pm.load(":/images/11.jpg");
if(load_result)
{
qDebug("Pixmap loaded succesfull!");
NewForm* anp = new NewForm;
qDebug("NewForm");
qDebug() << anp;
QLabel FullView = anp->findChild<QLabel>("FullView");
qDebug("FullView");
qDebug() << FullView;
FullView->setGeometry(QRect(10, 30, 465, 385));
FullView->setPixmap(QPixmap(QString::fromUtf8(":/images/11.jpg")));
FullView->setAlignment(Qt::AlignCenter);
}
else
qDebug("Pixmap not loaded!");in application console:
Pixmap loaded succesfull!
NewForm
NewForm(0x55cd13744330, name="NewForm")
FullView
QLabel(0x55cd134734a0, name="FullView")what's wrong?
-
@Adl78 said in not show image from resources in another window Qlabel:
FullView->setPixmap(QPixmap(QString::fromUtf8(":/images/11.jpg")));
Why don't you use pm here? No need to load the pixmap two times.
-
@Adl78 said in not show image from resources in another window Qlabel:
anp
you don't call show() on your new form
-
@jsulm
Because i check have image on resource or not. -
@J-Hilk
you don't call show() on your new formWindow already showed. if i add string - anp->show(); showing new window "New Form" with image. But i need only show image in window.
-
@Adl78 said in not show image from resources in another window Qlabel:
Because i check have image on resource or not.
That's clear. But you can do:
FullView->setPixmap(pm);
instead of loading the image second time:
FullView->setPixmap(QPixmap(QString::fromUtf8(":/images/11.jpg")));
-
@Adl78 said in not show image from resources in another window Qlabel:
Window already showed
Could you explain how your window is already shown given that
anp
is a local variable and you don't show it nor give it a parent? -
@JonB
in mainwindow.cpp this code showing NewForm window:void MainWindow::on_Menu_activated(const QString &arg1)
{
if(arg1=="New Form")
{
NewForm* anp = new NewForm;
anp->move(-50000,-50000);
anp->move(0,150);
anp->show();
hide();
}
} -
@Adl78
I don't understand: this code seems to be elsewhere than the code you showed at the start, that other code does anew NewForm
, this code here does anew NewForm
, those are two quite separate forms, there is no relationship between them.... -
@jsulm
Ok. I changed on FullView->setPixmap(pm); -
@JonB
This code shows a window in which there is a Qlabel and then the function in which I provided is called ... in it I load an image from the resources and it should be shown, but it is not shown. -
@Adl78 said in not show image from resources in another window Qlabel:
but it is not shown.
Because you create a new window in that function instead of using the one you already created. As pointed out by @JonB already...
-
@Adl78
The second code you show has noQLabel
. It shows some new, completely unrelatednew NewForm
being created. If you are not already you should familiarize yourself with the meaning of C++ instances.