Multiple scenes in one QGraphicview
-
This is my code ,
int check = 4 ; for(int i=0;i<check;i++) { ui->graphicsView->setFixedSize(215 , 110); ui->graphicsView->setSceneRect(0,0,215,110); ui->graphicsView->setScene(&m_Scene); m_Code->setWidth(35); m_Code->setHeight(70); m_Code->setPos(15,15); m_Scene.addItem( m_Code ); m_Scene.update(); m_Code->update(); m_Code->setText(ui->lineEdit_7->text()); m_Code->update(); m_Scene.update(); }In this m_Code means that every time the loop comes, the new shapes will be displayed in the Same QGraphicsView one by one.
I don't know how to do that,
How to display Multiple scenes in a single QGraphicsView. -
This is my code ,
int check = 4 ; for(int i=0;i<check;i++) { ui->graphicsView->setFixedSize(215 , 110); ui->graphicsView->setSceneRect(0,0,215,110); ui->graphicsView->setScene(&m_Scene); m_Code->setWidth(35); m_Code->setHeight(70); m_Code->setPos(15,15); m_Scene.addItem( m_Code ); m_Scene.update(); m_Code->update(); m_Code->setText(ui->lineEdit_7->text()); m_Code->update(); m_Scene.update(); }In this m_Code means that every time the loop comes, the new shapes will be displayed in the Same QGraphicsView one by one.
I don't know how to do that,
How to display Multiple scenes in a single QGraphicsView.@Ramkumar-Mohan said in Multiple scenes in one QGraphicview:
How to display Multiple scenes in a single QGraphicsView.
You can't, and wouldn't want to! A
QGraphicsViewis a view onto (an area of) oneQGraphicsScene, viaQGraphicsView::setScene(QGraphicsScene *scene). You can't have it view more than one scene! OTOH, it's fine to have multipleQGraphicsViews onto a singleQGraphicsScene, e.g. to view different areas.I don't know why you think you would want multiple
QGraphicsScenes nor what the code you show is trying to achieve. -
@Ramkumar-Mohan said in Multiple scenes in one QGraphicview:
How to display Multiple scenes in a single QGraphicsView.
You can't, and wouldn't want to! A
QGraphicsViewis a view onto (an area of) oneQGraphicsScene, viaQGraphicsView::setScene(QGraphicsScene *scene). You can't have it view more than one scene! OTOH, it's fine to have multipleQGraphicsViews onto a singleQGraphicsScene, e.g. to view different areas.I don't know why you think you would want multiple
QGraphicsScenes nor what the code you show is trying to achieve.@JonB Ok,
Header File ,
MainWindow.h
class MainWindow : public QMainWindow
{
Q_OBJECTQGraphicsScene m_Scene; QGraphicsScene m_Scene1;}
CPP File ,
MainWindow.CPP
int check =2 ;
for(int i=0 ; i<check ;i++)
{
if(i==0){ ui->graphicsView->setFixedSize(420 , 580); ui->graphicsView->setSceneRect(50,0,215,110); QThread::msleep(500); ui->graphicsView->setScene(&m_Scene); m_Code= new Code128Item(); m_Code->setWidth(35); m_Code->setHeight(70); m_Code->setPos(50,0); m_Scene.addItem( m_Code); m_Scene.update(); m_Code->update(); m_Code->setText(Data); m_Code->update(); m_Scene.update(); ui->graphicsView->setScene(&m_Scene); ui->graphicsView->update(); }else if(i==1)
{ui->graphicsView->setFixedSize(420 , 580); ui->graphicsView->setSceneRect(200,0,215,110); QThread::msleep(500); ui->graphicsView->setScene(&m_Scene1); m_Code->setWidth(35); m_Code->setHeight(70); m_Code->setPos(200,0); m_Scene1.addItem(m_Code); m_Scene1.update(); m_Code->update(); m_Code->setText("Data1"); m_Code->update(); m_Scene1.update(); ui->graphicsView->setScene(&m_Scene1); ui->graphicsView->update();}
}I wrote This code ,
In this the text named data should be placed at (0,0) position, similarly the text named Data1 should be placed at (200,0) position. I don't know what is wrong with this code.
-
@JonB Ok,
Header File ,
MainWindow.h
class MainWindow : public QMainWindow
{
Q_OBJECTQGraphicsScene m_Scene; QGraphicsScene m_Scene1;}
CPP File ,
MainWindow.CPP
int check =2 ;
for(int i=0 ; i<check ;i++)
{
if(i==0){ ui->graphicsView->setFixedSize(420 , 580); ui->graphicsView->setSceneRect(50,0,215,110); QThread::msleep(500); ui->graphicsView->setScene(&m_Scene); m_Code= new Code128Item(); m_Code->setWidth(35); m_Code->setHeight(70); m_Code->setPos(50,0); m_Scene.addItem( m_Code); m_Scene.update(); m_Code->update(); m_Code->setText(Data); m_Code->update(); m_Scene.update(); ui->graphicsView->setScene(&m_Scene); ui->graphicsView->update(); }else if(i==1)
{ui->graphicsView->setFixedSize(420 , 580); ui->graphicsView->setSceneRect(200,0,215,110); QThread::msleep(500); ui->graphicsView->setScene(&m_Scene1); m_Code->setWidth(35); m_Code->setHeight(70); m_Code->setPos(200,0); m_Scene1.addItem(m_Code); m_Scene1.update(); m_Code->update(); m_Code->setText("Data1"); m_Code->update(); m_Scene1.update(); ui->graphicsView->setScene(&m_Scene1); ui->graphicsView->update();}
}I wrote This code ,
In this the text named data should be placed at (0,0) position, similarly the text named Data1 should be placed at (200,0) position. I don't know what is wrong with this code.
@Ramkumar-Mohan
I don't see what "m_Code" is, but why not simply add two texts to one scene? -
@Ramkumar-Mohan
I don't see what "m_Code" is, but why not simply add two texts to one scene?@Asperamanca
m_Code Means,MainWindow.h
class MainWindow : public QMainWindow
{
Q_OBJECTQGraphicsScene m_Scene; QGraphicsScene m_Scene1; Code128Item * m_Code;}
-
@Asperamanca
m_Code Means,MainWindow.h
class MainWindow : public QMainWindow
{
Q_OBJECTQGraphicsScene m_Scene; QGraphicsScene m_Scene1; Code128Item * m_Code;}
@Ramkumar-Mohan
So just create 2 items like m_Code, instead of 2 scenes -
@Ramkumar-Mohan said in Multiple scenes in one QGraphicview:
How to display Multiple scenes in a single QGraphicsView.
You can't, and wouldn't want to! A
QGraphicsViewis a view onto (an area of) oneQGraphicsScene, viaQGraphicsView::setScene(QGraphicsScene *scene). You can't have it view more than one scene! OTOH, it's fine to have multipleQGraphicsViews onto a singleQGraphicsScene, e.g. to view different areas.I don't know why you think you would want multiple
QGraphicsScenes nor what the code you show is trying to achieve.@JonB said in Multiple scenes in one QGraphicview:
I don't know why you think you would want multiple
QGraphicsScenesLike @Asperamanca says too.
-
@JonB said in Multiple scenes in one QGraphicview:
I don't know why you think you would want multiple
QGraphicsScenesLike @Asperamanca says too.
Now , working fine , Thank You
-
@JonB said in Multiple scenes in one QGraphicview:
I don't know why you think you would want multiple
QGraphicsScenesLike @Asperamanca says too.
-
@Ramkumar-Mohan
I imagine so, why not? Certainly assuming you can print oneQGraphicsViewyou can print many. -
@Ramkumar-Mohan
I imagine so, why not? Certainly assuming you can print oneQGraphicsViewyou can print many.I am a beginner in qt and I don't really understand its concept.
-
@Ramkumar-Mohan
I don't see what "m_Code" is, but why not simply add two texts to one scene?QGraphicsView Items should be set in this way ....
how to set the graph scale...
Thank you.
-
QGraphicsView Items should be set in this way ....
how to set the graph scale...
Thank you.
@Ramkumar-Mohan
Not sure what the question here is. You can transform individual items (scale, rotate, shear), and you can do the same for the whole GraphicsView.As for printing: You can grab a QPixmap or QImage of each GraphicsView and print it, for example.
-
@Ramkumar-Mohan
Not sure what the question here is. You can transform individual items (scale, rotate, shear), and you can do the same for the whole GraphicsView.As for printing: You can grab a QPixmap or QImage of each GraphicsView and print it, for example.
This post is deleted!