qt 将当前窗口保存为图片

复制代码
bool BasicDotChart::saveAsImage(const QString &path)
{
    // 获取窗口的 QPixmap
    QPixmap pixmap = this->grab();
    // 弹出保存文件对话框,选择保存位置和文件格式
    QString filePath = path + "/" + QDateTime::currentDateTime().toString("yyyy-mm-dd-hh-mm-ss") + "_dotchat.png";
    qDebug()<<"filePath = "<<filePath;
    if (!filePath.isEmpty()) {
        // 保存 QPixmap 到文件
        pixmap.save(filePath);
        qDebug()<<"点位图保存成功 : "<<filePath;
        return true;
    }
    qDebug()<<"点位图保存失败!";
    return false;
}
复制代码

 

posted @   雾枫  阅读(107)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 清华大学推出第四讲使用 DeepSeek + DeepResearch 让科研像聊天一样简单!
· 推荐几款开源且免费的 .NET MAUI 组件库
· 实操Deepseek接入个人知识库
· 易语言 —— 开山篇
· Trae初体验
点击右上角即可分享
微信分享提示