Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Save Graphics View Scene
Forum Update on Monday, May 27th 2025

Save Graphics View Scene

Scheduled Pinned Locked Moved Unsolved General and Desktop
scenesave
6 Posts 2 Posters 5.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mandruk1331
    wrote on 30 Jan 2016, 10:09 last edited by
    #1

    How I can save the scene, so it would be a .jpg file or a .gif file?
    QString fileName = "path";
    QPixmap pixMap = QPixmap::grabWidget(ui->graphicsView_animation, 100,100,10,10);
    pixMap.save(fileName);
    I have tried the code above but it didn't work

    Mandruk1331

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on 30 Jan 2016, 10:30 last edited by
      #2

      QPixmap::grabWidget is obsolete. Use QWidget::grab() instead.

      M 1 Reply Last reply 30 Jan 2016, 13:13
      0
      • ? A Former User
        30 Jan 2016, 10:30

        QPixmap::grabWidget is obsolete. Use QWidget::grab() instead.

        M Offline
        M Offline
        mandruk1331
        wrote on 30 Jan 2016, 13:13 last edited by
        #3

        @Wieland I can't make an img from Graphics View which is moving rectangles, it makes a blank img, why?

        Mandruk1331

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on 30 Jan 2016, 13:23 last edited by
          #4

          Works for me:

              QGraphicsRectItem *rect = new QGraphicsRectItem;
              rect->setRect(QRectF(0,0,100,60));
              QGraphicsScene *scene = new QGraphicsScene(this);
              ui->graphicsView->setScene(scene);
              scene->addItem(rect);
          
              const QPixmap pixmap = ui->graphicsView->grab();
              const QString fileName("/home/pw/image.png");
              qDebug() << pixmap.save(fileName);
          
          M 1 Reply Last reply 30 Jan 2016, 13:30
          2
          • ? A Former User
            30 Jan 2016, 13:23

            Works for me:

                QGraphicsRectItem *rect = new QGraphicsRectItem;
                rect->setRect(QRectF(0,0,100,60));
                QGraphicsScene *scene = new QGraphicsScene(this);
                ui->graphicsView->setScene(scene);
                scene->addItem(rect);
            
                const QPixmap pixmap = ui->graphicsView->grab();
                const QString fileName("/home/pw/image.png");
                qDebug() << pixmap.save(fileName);
            
            M Offline
            M Offline
            mandruk1331
            wrote on 30 Jan 2016, 13:30 last edited by
            #5

            @Wieland I think you forgot pixmap.save(fileName,"jpg"). Thx it worked.

            Mandruk1331

            1 Reply Last reply
            0
            • ? Offline
              ? Offline
              A Former User
              wrote on 30 Jan 2016, 13:37 last edited by
              #6

              bool QPixmap::save(const QString & fileName, const char * format = 0, int quality = -1) const

              "If format is 0, an image format will be chosen from fileName's suffix." (see QPixmap documentation)

              So you can say pixmap.save("/home/pw/myfile.jpg") and it will automatically detect the ".jpg" suffix. If you want to save the image without a suffix you must specify what file format you want to use: pixmap.save("/home/pw/myfile", "JPG") (see supported file formats).

              1 Reply Last reply
              0

              4/6

              30 Jan 2016, 13:23

              • Login

              • Login or register to search.
              4 out of 6
              • First post
                4/6
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved