Hi,
how can i display a .svg in a QGraphicsView?
i tried the following but nothing is displayed:
Code:
// ui->gview is a QGraphicsView object QGraphicsScene scene; ui->gview->setScene(&scene); ui->gview->show();
Thanks,
S
Printable View
Hi,
how can i display a .svg in a QGraphicsView?
i tried the following but nothing is displayed:
Code:
// ui->gview is a QGraphicsView object QGraphicsScene scene; ui->gview->setScene(&scene); ui->gview->show();
Thanks,
S
Have you checked that the file was successfully loaded in the QPixmap? QPixmap::isNull() or QPixmap::load() are your friends.
Anyway, a quick look at the documentation turned up QGraphicsSvgItem.
the following code works now, but i dont know how to resize the svg img to the size of the QGraphicsScene...ideas? QGraphicsScene cannot display the entire svg, bc the svg is too large...
Code:
ui->gview->setScene(scene); ui->gview->show();
edit: i just saw from subforum...
Since you do not explicitly set a scene rectangle to your QGraphicScene, it automatically grows to the size of the item.
Do you want the view to display the whole item? Then another quick look at the documentation for QGraphicsView should let you know how to have the item fit in the view.
yes, i want to get the entire svg visible...
the following does not work... the svg is way too tiny now...
Code:
scene->addItem(item); ui->gview->setScene(scene); ui->gview->fitInView(scene->sceneRect(), Qt::KeepAspectRatio); ui->gview->show(); qDebug() << "ui->graphicsView->size(): " << ui->graphicsView->size(); qDebug() << "scene->sceneRect().size(): " << scene->sceneRect().size();
svg size: 1039 x 745 pixel
output:
ui->graphicsView->size(): QSize(100, 30)
scene->sceneRect().size(): QSizeF(831, 596)
why is that?
There is no such thing as QGraphicsView::fitItem(). Your program cannot be compiled, so I am not surprised that it "does not work".
The scene and view have separate coordinate systems. You can render different parts of a scene in several views.
copy paste error... it should be: fitInView
it compiles, but the size of the svg in the QGraphicsView is tiny....any idea?
see here:
Attachment 11303
Hello,
I have the same. My SVG is very tiny in the view after fitInView. Any Solution?