QGraphicsView has ~1 pixel margin for QPixmap



  • I've created a QMainWindow, which sets it's center widget to a QGraphicsView.
    The QGraphicsView displays a QGraphicsScene with a single QPixmap inside it.

    The whole thing spans across all Screens and just displays a screenshot of all screens in the QPixmap.

    This is my constructor:

    // These are in the initializer list
    auto scene = new QGraphicsScene;
    auto view = new QGraphicsView(scene, this);
    
    // Gets a Screenshot of all screens
    scene->addPixmap(Screenshot::getScreenshotFull());
    
    view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    view->show();
    
    setCentralWidget(view);
    

    Now once this window gets displayed, the Screenshot is moved to the right and down by about one pixel. (Which means there is a white border at the left and top screen)

    How it should be:
    0_1518270814992_without.PNG

    How it actually is (I've made the top border red, left border white):
    0_1518270850998_with.PNG

    It seems like the QGraphicsScene indents all contents by one pixel so it is "visually inside" the outer widget/container (QGraphicsView)

    Is there any way to get around this and remove that border?

    When I used a QLabel and set the Pixmap via that, there was no border. I moved to the QGraphicsView because apparently that one is better if I want to draw plenty of rectangles onto it later on.. is that correct?

    This whole thing is a Screenshot tool, so only an overlay where the user can crop out a rectangle (and also I can highlight windows with rectangles), is it a good idea for that to use a QMainWindow and by code only or should I use .ui files? Also is QGraphicsView the right option here? I want to draw a rectangle whenever the user hovers over certain areas.

    Thanks.



  • @mrousavy The solution is to set no frame style.

    view->setFrameStyle(QFrame::NoFrame);
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.