1

I am trying to design a custom widget with a QGraphicsScene and a pixmap item in it. I can see my item but there is a rectangle outside the scene. I found out that this is the scene rectangle. How can I prevent Qt from drawing scene rectangle?

QGraphicsView* view = new QGraphicsView(this);
QGraphicsScene* scene = new QGraphicsScene(view);
QGraphicsPixmapItem* pix1 = new QGraphicsPixmapItem(QPixmap(":/images/img/img1.png"));
scene->addItem(pix1);
view->setScene(scene);

Output 1

scene->setSceneRect(0, 0, 250, 150);

Output 2

Emrah
  • 13
  • 2

1 Answers1

1

I believe (please be gentle I'm new fairly new to this also plus this is my first answer on here), that Qt isn't supposed to draw the scene rectangle, (or at least not by default).

I think that maybe what you are seeing is the edges of the QGraphicsView that is rendering your scene. There are properties that you can set on your QGraphicsView object that determine the 'look' of your view.

I hope I'm not on the wrong tangent here, but if it is your QGraphicsView borders that you're seeing you can probably remove them by calling the setViewportMargins() function that it inherits from QAbstractScrollArea.

Hope this helps. Cheers!

  • Thank you. That was the problem. I solved it by making Graphicsview borderless. I have thought that was scene's border since view resizes itself to cover the scene. – Emrah Dec 14 '15 at 17:57