Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QGraphicsView has ~1 pixel margin for QPixmap

QGraphicsView has ~1 pixel margin for QPixmap

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 1 Posters 1.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mrousavy
    wrote on last edited by mrousavy
    #1

    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.

    M 1 Reply Last reply
    0
    • M mrousavy

      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.

      M Offline
      M Offline
      mrousavy
      wrote on last edited by
      #2

      @mrousavy The solution is to set no frame style.

      view->setFrameStyle(QFrame::NoFrame);
      
      1 Reply Last reply
      3

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved