Why is a rectangle partly outside of view drawn as a triangle?
Asked Answered
H

4

16

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!

enter image description here

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

Hargreaves answered 18/9, 2014 at 8:53 Comment(10)
Does the error go away with view.setSceneRect(-10, -10, 120, 120)?Chatterton
@vahancho Because it shows the triangle for -60. It doesn't always do it. I will update the question a bit with this information.Hargreaves
@AaronDigulla No, never if the rectangle is fully visible. The triangle is only displayed for some cases where the rectangle is not fully visible.Hargreaves
this is defiantly a bug! Report it to Qt!Onieonion
FWIW: Your example works just fine with PyQt 4.9.6 (Qt 4.8.4) and python 2.7.Diminutive
Okay, seems to be a bug. I will file it with PySide.Hargreaves
@Trilarion It'd be a good idea to link the bug report here to help potential Googlers, by the way.Stiff
Also seen in PyQt4. Interestingly, if you resize the window, then return to original size, the triangle becomes the expected squares-corner.Lowborn
I saw this happing in Mac OS and Linux as well. Thought it was a strange bug in my code..Burstone
@Trilarion did you ever file a bug report and get a response?Hass
H
0

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.

Hargreaves answered 29/7, 2016 at 20:12 Comment(0)
J
0

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.

Jilljillana answered 23/2, 2015 at 20:3 Comment(0)
E
0

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)

Exocarp answered 12/5, 2016 at 14:57 Comment(0)
E
0

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()
Emeraldemerge answered 29/7, 2016 at 18:2 Comment(1)
What is happening for you is a bugEmeraldemerge
H
0

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.

Hargreaves answered 29/7, 2016 at 20:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.