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
QtWS25 Last Chance

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.
  • mandruk1331M Offline
    mandruk1331M Offline
    mandruk1331
    wrote on 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 last edited by
      #2

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

      mandruk1331M 1 Reply Last reply
      0
      • ? A Former User

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

        mandruk1331M Offline
        mandruk1331M Offline
        mandruk1331
        wrote on 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 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);
          
          mandruk1331M 1 Reply Last reply
          2
          • ? A Former User

            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);
            
            mandruk1331M Offline
            mandruk1331M Offline
            mandruk1331
            wrote on 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 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

              • Login

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