{
QImage *ppm = new QImage(filename)
label = new QLabel()
printf("ppm->width()=%d, ppm->height()=%d\n",ppm->width(), ppm->height())//获取图片的宽度和高度
label->setPixmap(QPixmap::fromImage(*ppm))
this->setWidget(label)
/*设置窗口最大高度和宽度为1024*768*/
this->setMaximumHeight(768)
this->setMaximumWidth(1024)
this->resize(QSize( ppm->width()+5, ppm->height() +5))
return
}
//假如label的名称是show_labelvoid xx::show(const QSt//假如label的名称是show_label
void xx::show(const QString &file)
{
QPixmap pix
pix.load(file)
pix=pix.scaled(ui->show_label->width(),ui->show_label->height())
ui->show_label->setPixmap(fix)
}
int main()
{
show(tr("./images/open.png"))//显示/images/open.png的图片
return 0
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)