Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Save Graphics View Scene

    General and Desktop
    scene save
    2
    6
    4612
    Loading More Posts
    • 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.
    • mandruk1331
      mandruk1331 last edited by

      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 Reply Quote 0
      • ?
        A Former User last edited by

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

        mandruk1331 1 Reply Last reply Reply Quote 0
        • mandruk1331
          mandruk1331 @Guest last edited by

          @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 Reply Quote 0
          • ?
            A Former User last edited by

            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);
            
            mandruk1331 1 Reply Last reply Reply Quote 2
            • mandruk1331
              mandruk1331 @Guest last edited by

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

              Mandruk1331

              1 Reply Last reply Reply Quote 0
              • ?
                A Former User last edited by

                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 Reply Quote 0
                • First post
                  Last post