您的位置:首页 > 产品设计 > UI/UE

Qt:将quick的控件图像保存为QImage

2015-08-20 09:18 344 查看
直接上代码

注:C++11写法,需要编译器支持C++11标准才可以正常编译

QImage itemToImage(QObject *object)
{
    auto item = qobject_cast<QQuickItem*>(object);
    if(!item) { return QImage(); }

    QEventLoop eventLoop;
    QImage buf;
    auto grad = item->grabToImage();

    auto c = QObject::connect(grad.data(), &QQuickItemGrabResult::ready, [&]()
    {
        buf = grad->image();
        eventLoop.exit();
    });
    eventLoop.exec();
    QObject::disconnect(c);

    return buf;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: