Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QGraphicsScene grab pixmap



  • class GraphicsScene : public QGraphicsScene
    
    void GraphicsScene::copy()
    {
        QRectF rect(startPnt, endPnt);
        QPixmap pixmap = QPixmap::grabWindow(QApplication::desktop()->winId(), rect.x(), rect.y(), rect.width(), rect.height()); // but grab window below the QWidget
        //QPixmap pixmap = this->grab(rect); // has no member named ‘grab’
        QApplication::clipboard()->setPixmap(pixmap, QClipboard::Clipboard);
    }
    

  • Lifetime Qt Champion

    @sonichy
    https://doc.qt.io/qt-5/qgraphicsscene.html#render
    There is even an example:

    QGraphicsScene scene;
    scene.addItem(...
    ...
    QPrinter printer(QPrinter::HighResolution);
    printer.setPaperSize(QPrinter::A4);
    
    QPainter painter(&printer);
    scene.render(&painter);
    

    You can use a pixmap instead of printer...


Log in to reply