• Qt label加载图片,父窗口便利子窗口控件


    int size = 12;
    for (int i = 1; i <= size; i++)
    {
    QString filename = QString("./image/%2%3").arg(i).arg(".jpg");
    //qDebug() << "filename:" << filename << endl;
    QImage* img = new QImage, *scaledimg = new QImage;//分别保存原图和缩放之后的图片
    //加载图像,如加载失败,则弹出对话框,提示打开图像失败
    if (!(img->load(filename)))
    {
    QMessageBox::information(this, QStringLiteral("打开图像失败"), QStringLiteral("打开图像失败!"));
    delete img;
    return;
    }

    //获取图像的宽度和高度
    int ImageWidth = img->width(), ImageHeight = img->height();
    //定义缩放的图片的宽度和高度
    int SmallWidth, SmallHeight;
    //设置label的位置和宽高

    int Mul; //记录图片与label大小的比例,用于缩放图片
    if (ImageWidth / 200 >= ImageHeight / 150)
    {
    Mul = ImageWidth / 200;
    }
    else
    {
    Mul = ImageHeight / 150;
    }
    SmallWidth = ImageWidth / Mul;
    SmallHeight = ImageHeight / Mul;
    *scaledimg = img->scaled(SmallWidth, SmallHeight, Qt::KeepAspectRatio);

    QString lablename = "DeviceImage" + QString::number(i, 10);
    QLabel *label = ui.DeviceMonitorgroupBox->findChild<QLabel *>(lablename);
    if (label)
    {
    label->setPixmap(QPixmap::fromImage(*scaledimg));
    }
    else
    return;

    QString devicename = "DeviceName" + QString::number(i, 10);
    QLabel *name = ui.DeviceMonitorgroupBox->findChild<QLabel *>(devicename);
    if (name)
    {
    name->setText(QStringLiteral("设备在线"));
    name->setAlignment(Qt::AlignHCenter);
    }
    else
    return;

    }

  • 相关阅读:
    在子Repeater调用父Repeater里的数据
    使用事务范围实现隐式事务
    关于TransactionScope分布式事务在Oracle下的运作
    C#枚举类型的使用示例
    ORACLE分区表发挥性能
    oracle 批处理 执行 sql
    连接查询_左连接/右连接/全连接的区别
    转: C#的25个基础概念
    bat文件编写
    Nginx 远程安全漏洞
  • 原文地址:https://www.cnblogs.com/LuckCoder/p/10862809.html
Copyright © 2020-2023  润新知