• Qt 将QGraphicsView视图界面保存为图片


    需求: QGraphicsView 编辑完成之后,需要将界面保存为图片导出.

    QPixmap pix=ui->graphicsView->grab();

     展示代码示例:

     1 #include <QDialog>
     2 #include <QLabel>
     3 void MainWindow::on_pushButton_clicked()
     4 {
     5     QPixmap pix=ui->graphicsView->grab();
     6  
     7     QDialog *dialog=new QDialog;
     8  
     9     dialog->setWindowTitle("图片展示");
    10  
    11     QHBoxLayout *layout=new QHBoxLayout;
    12     QLabel *label=new QLabel;
    13     label->resize(800,480);
    14     pix=pix.scaled(label->width(),label->height());
    15     label->setPixmap(pix);
    16     layout->addWidget(label);
    17  
    18     dialog->setLayout(layout);
    19     dialog->show();
    20     dialog->exec();
    21  
    22     delete dialog;
    23 }
  • 相关阅读:
    maven
    sublime text
    ios category
    python
    activiti
    出版社
    gradle
    selenium
    spring
    Ansible状态管理
  • 原文地址:https://www.cnblogs.com/ybqjymy/p/16285185.html
Copyright © 2020-2023  润新知