I'm trying to show an image in QGraphicsView, but for some reason the top-right corner starts in the middle of the QGraphicsView.
Also, how to make it fit the QGraphicsView?
Here's my code:
Mat frameMat;
videoReader >> frameMat;
_graphicsScene = make_unique<QGraphicsScene>(0, 0, 300, 300);
ui.graphicsView->setScene(_graphicsScene .get());
_graphicsScene ->setBackgroundBrush(Qt::blue);
QImage qImg
(frameMat.
data, frameMat.
cols, frameMat.
rows, frameMat.
step,
QImage::Format_RGB888);
auto pixImg
= QPixmap::fromImage(qImg
);
_graphicsScene ->addItem(item);
Mat frameMat;
videoReader >> frameMat;
_graphicsScene = make_unique<QGraphicsScene>(0, 0, 300, 300);
ui.graphicsView->setScene(_graphicsScene .get());
_graphicsScene ->setBackgroundBrush(Qt::blue);
QImage qImg(frameMat.data, frameMat.cols, frameMat.rows, frameMat.step, QImage::Format_RGB888);
auto pixImg = QPixmap::fromImage(qImg);
auto item = new QGraphicsPixmapItem(pixImg);
_graphicsScene ->addItem(item);
To copy to clipboard, switch view to plain text mode
Here what I get when I run my code:
Untitled.jpg
Bookmarks