How to save only the scene in graphics view. actual scene width and scene height.
-
I wrote this code ,
m_Scene99.update(); QThread::msleep(500); ui->graphicsView_103->setScene(&m_Scene99); m_Barcode99 = new Code128Item(); m_Barcode99->setWidth(200); m_Barcode99->setHeight(70); m_Barcode99->setPos(0,0); m_Scene99.addItem( m_Barcode99); m_Scene99.update(); m_Barcode99->update(); m_Barcode99->setText(ui->lineEdit_7->text()); m_Barcode99->update(); m_Scene99.update(); ui->graphicsView_103->setScene(&m_Scene99); ui->graphicsView_103->update(); QThread::msleep(500); QImage img(m_Scene99.width(),m_Scene99.height,QImage::Format_ARGB32_Premultiplied); QPainter p(&img); m_Scene99.render(&p); p.end(); img.save("img1.png");In this case, I saved 10 Images in different scenes in different QGraphicsview , it is saved but another scene is placed on top of one scene,
why is this happenning , here is what going wrong,
Thank you,
-
Hi,
Why all the sleep in your code ? It blocks the event loop.
Also, why not print the images directly rather than going through a QGraphicsScene/View ?
-
Hi,
Why all the sleep in your code ? It blocks the event loop.
Also, why not print the images directly rather than going through a QGraphicsScene/View ?
I don't know how to print images directly.
-
I don't know how to print images directly.
@Ramkumar-Mohan
Then you should look at QPrinter Class. https://stackoverflow.com/questions/68764447/qprinter-image-gets-cut-off-when-printing shows some sample code, adapt that to your case. -
@Ramkumar-Mohan
Then you should look at QPrinter Class. https://stackoverflow.com/questions/68764447/qprinter-image-gets-cut-off-when-printing shows some sample code, adapt that to your case.Ok ,
one more doubt,
how to save only the scene in QGraphicsview ,
Eample,
I have Highlighed in the empty space .
I want to scene only the barcode in my first post and skip the empty space in it.
(or)
How to set Scene width and height ,
No matter how big the barcode is generated, it should only be in the width i give.
how can i do,,,Thanks,
-
Ok ,
one more doubt,
how to save only the scene in QGraphicsview ,
Eample,
I have Highlighed in the empty space .
I want to scene only the barcode in my first post and skip the empty space in it.
(or)
How to set Scene width and height ,
No matter how big the barcode is generated, it should only be in the width i give.
how can i do,,,Thanks,
@Ramkumar-Mohan
Neither @SGaist nor I understand what/why you are doing with a graphics scene or view.You seem to have an image which can be printed directly. If the empty space is in the image already then I would guess you must either remove it from the image or only copy the desired area into the
QPainterby usingQPainter::setClipRect(), see https://doc.qt.io/qt-6/qpainter.html#clipping. -
@Ramkumar-Mohan
Neither @SGaist nor I understand what/why you are doing with a graphics scene or view.You seem to have an image which can be printed directly. If the empty space is in the image already then I would guess you must either remove it from the image or only copy the desired area into the
QPainterby usingQPainter::setClipRect(), see https://doc.qt.io/qt-6/qpainter.html#clipping.I don't have image already, I generate barcode, as different scene in different graphicsview, I save the scene in it as image, for each barcode generated width is taken as different, one barcode size is small and another barcode is set in GrpahicsView.
Small generated barcode is getting empty space, large generated barcode is not getting empty space, when I print them one by one. Measurements are variable print.

-
I don't have image already, I generate barcode, as different scene in different graphicsview, I save the scene in it as image, for each barcode generated width is taken as different, one barcode size is small and another barcode is set in GrpahicsView.
Small generated barcode is getting empty space, large generated barcode is not getting empty space, when I print them one by one. Measurements are variable print.

@Ramkumar-Mohan said in How to save only the scene in graphics view. actual scene width and scene height.:
I don't have image already, I generate barcode, as different scene in different graphicsview, I save the scene in it as image
As said previously, we do not know why you are introducing scenes, views, or multiple ones of each. But in any case you say you generate an image to print, by whatever means. So the suggestions for setting the area you want printed so that it excludes some blank area I made in my previous post still pertain.