需求: QGraphicsView 编辑完成之后,需要将界面保存为图片导出.
QPixmap pix=ui->graphicsView->grab();
展示代码示例:
#include <QDialog> #include <QLabel> void MainWindow::on_pushButton_clicked() { QPixmap pix=ui->graphicsView->grab(); QDialog *dialog=new QDialog; dialog->setWindowTitle("图片展示"); QHBoxLayout *layout=new QHBoxLayout; QLabel *label=new QLabel; label->resize(800,480); pix=pix.scaled(label->width(),label->height()); label->setPixmap(pix); layout->addWidget(label); dialog->setLayout(layout); dialog->show(); dialog->exec(); delete dialog; }