我在主窗口中创建了一个标签,其大小设置为 200x300px。现在单击按钮,我需要查看其中的图像。这是按钮的插槽功能。
void MainWindow::function1(){
QImage img;
img.loadFromData("test.jpg");
img = img.scaled(200, 300, Qt::KeepAspectRatio, Qt::SmoothTransformation);
label->setPixmap(QPixmap::fromImage(img));
}
问题是编译没有错误,但不显示图像。按下按钮时插入,它QImage::scaled: Image is a null image
在 IDE 中显示,我在 qt 中是新的。我会非常感谢任何建议。
谢谢你