需求: 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 }