Friday, 15 May 2015

c++ - Unwanted margin inside QGraphicsView with Scrollbars -


I am developing a video player using QGraphicsView to display the video. Displaying a QGraphicsView with a single QGraphicsPixmapItem , containing the current video frame. The background of the scene is black.

As long as the frame is smaller than the footage, everything is fine, the video frame is displayed at the center of view and the rest of the view is black. When the scene is the same size as the frame, only the frame is shown, (obviously) no background. When the video frame is larger than the view, scrollbars are shown so that users can see the other parts of the scroll.

Issue: When scrollbars are shown, it is possible to scroll the video frame past a margin of 8 pixels below and on the right side where the background is visible if the video is more than the frame view, then any The background should not be visible and the video frame should not be scrolled past.

I reduced the problem into a short source code that shows the problem, showing 200x200 px red QPixmap in a QGraphicsView with a green background Used to be.

  #include & lt; QtGui / QApplication & gt; # Include & lt; QMainWindow & gt; # Include & lt; QGraphicsScene & gt; # Include & lt; QGraphicsView & gt; Int main (int argc, char * argv []) {Q Application app (argc, argv); QMainWindow window; Cupismap Pixmap (200, 200); Pixmap.fill (QColor (255, 0, 0)); QGraphicsScene view (and window); Scene.addPixmap (Pixmap); See QGraphicsView (and window); View.setBackgroundBrush (QColor (0, 255, 0)); View.setScene (& amp; View); Window.setCentralWidget (& amp; see); Window.show (); Window. Size (199, 199); Return app.exec (); } I have also made a picture of the problem (black border has not been included in the example code):  

On the left window, click the code> QGraphicsView < / Code> is similar to the same shape, which is slightly shorter on the right window, so scrollbars are shown. And the background is also visible (it should not be visible).

I have already tried to locate the scene and set other attributes of QWidget , QGraphicsView and QGraphicsScene But with the problem nothing changed.

I also said that there is a bug in my QT / KDE version and tried to run out the problem in a virtual machine to run the example problem.

I do not know when there are scrollbars, the background is displayed suddenly. How can I get rid of it? If this is not possible, do you have the idea of ​​how I can work around it?

Thanks in advance.

What you see is the area of ​​the window beyond the QGraphicsView; You may also know that You can resize the window and display more limits.

To fix this, constrain the size of the window to the size of the QGraphicsView as you have not set it in your example code, it will be the size of the pixmap.

Therefore, after declaring the window, add these lines: -

  SetMaximumWidth (200); Window.setMaximumHeight (200);   

By doing so, the size of the window will be restricted to the size of those values, so if you need to resize it apart, you will see a larger QGraphicsView and QGraphicsScene Will be required.

No comments:

Post a Comment