问题
I use the Python-Qt bindings from PySide and I want to draw a scene with amongst others a rectangle and the rectangle is not fully visible because the view should only show a part of the scene where the rectangle is not fully contained.
Here is a minimal example:
from PySide.QtGui import *
app = QApplication([])
scene = QGraphicsScene()
scene.addRect(0, 0, 100, 100)
view = QGraphicsView(scene)
view.setSceneRect(-60, 20, 100, 100)
view.show()
app.exec_()
I expect to see the lower part of a rectangle instead I see the lower part of a triangle!
It seems like the lower right corner of the rectangle is not taken into account.
The triangle only appears for special cases (like the special scene rect in the example) and does never occur if the full rectangle is visible.
Is this a bug or am I doing something wrong? Can it be fixed?
My system: Python 3.3 + PySide 1.2.2 (64 bit) on Windows 7
回答1:
Try drawing the rectangle with
import pygame
pygame.draw.rect(x, y, width, length)
See if that works. This is definitely a bug, so work around it.
回答2:
Had the same problem. It works if you use a GL widget:
from PySide import QtOpenGL
view.setViewport(QtOpenGL.QGLWidget())
(Python 2.7.6, PySide 1.2.1 x64 (Qt 4.8.5) on Windows 7)
回答3:
Try :
import pygame
from livewires import *
rectangle = rect(x, y, width, height) #note that the size is in pixels
while not keyboard.is_pressed(K_escape)
rectangle.erase()
rectangle.draw()
screen.update()
回答4:
It was a bug and it is fixed in the meantime, at least for some combinations of Qt and Python.
I now use Windows 10, Python 3.5, PyQt5 and the rectangle is shown as rectangle.
It's difficult to find out for which versions of PySide/PyQt and Qt 4.X or 5.x and Python 2.X or 3.X or Windows, Linux, Mac .. the bug is present and for which not. I did not erport the error but I guess since it works right now with what I have the bug would not be top priority for anyone and/or may already be fixed.
来源:https://stackoverflow.com/questions/25908244/why-is-a-rectangle-partly-outside-of-view-drawn-as-a-triangle