Important: Please read the Qt Code of Conduct -

How to show QGraphicsScene background and border but do not save into image ?

  • And why QGraphicsScene background fill full of QGraphicsView ?

    void MainWindow::open(QString filepath)
        QPixmap pixmap(filepath);
        QGraphicsPixmapItem *GPI = scene->addPixmap(pixmap);
        GPI->setFlags(QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsMovable);  
        scene->setSceneRect(0, 0, pixmap.width(), pixmap.height());
    void MainWindow::save(QString filepath)
        QSize size(scene->width(), scene->height());
        QImage image(size, QImage::Format_ARGB32);
        QPainter painter(&image);

  • Moderators

    try painting the background pixmap in QGraphicsView::drawBackground(), this way it shouldn't be taken into account by QGraphicsScene::render()

  • @raven-worx OK!


Log in to reply