[PyQt] strange bug re graphics scene in PyQt 5.7

oliver oliver.schoenborn at gmail.com
Thu Sep 8 20:39:52 BST 2016


OK so I can't make it any simpler than this folks, it MUST be a bug in
either Qt 5.7 or PyQt 5.7, please can someone run this and confirm they see
the ellipse drawn beyond the graphics view borders, without having to do
anything else:

from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication, QGraphicsView, QGraphicsScene,
QHBoxLayout, QWidget, QLabel
from PyQt5.QtWidgets import QGraphicsProxyWidget, QGraphicsObject,
QGraphicsEllipseItem
from PyQt5.QtGui import QBrush


class MyGraphicsItem(QGraphicsObject):

    def __init__(self):
        QGraphicsObject.__init__(self)

        # next line could be any type of graphics item:
        rect_item = QGraphicsEllipseItem(0, 0, 100, 100, self)
        # effect easier to see if paint black:
        rect_item.setBrush(QBrush(Qt.SolidPattern))

        label_item = QGraphicsProxyWidget(self)
        # *** Next line must be there for effect to be visible, but could
be any other type of widget
        label_item.setWidget(QLabel('a'*30))

    def paint(self, painter, option, widget=None):
        return

    def boundingRect(self):
        return self.childrenBoundingRect()


def show_problem():
    app = QApplication([])

    widget = QWidget()
    layout = QHBoxLayout()
    widget.setLayout(layout)

    view = QGraphicsView()
    scene = QGraphicsScene()
    view.setScene(scene)

    scene.addItem(MyGraphicsItem())  # *** effect only there if more than 1
item
    scene.addItem(MyGraphicsItem())

    layout.addWidget(view)

    widget.setGeometry(100, 100, 50, 50)
    widget.show()
    app.exec()


show_problem()



The 3 necessary conditions are:

   - more than one MyGraphicsItem instance in the scene (positions don't
   matter, but they have to stretch partly outside the view)
   - each instance contains
   - a proxy widget item (containing any widget, here a label is used)
      - a regular item (here a black ellipse is used, effect is then
      obvious)

Oliver


Oliver
Open Source contributions: PyPubSub <http://pubsub.sf.net/>, nose2pytest
<https://github.com/schollii/nose2pytest>, Lua-iCxx
<http://lua-icxx.sf.net/>, iof <http://iof.sf.net/>
StackOverflow <http://stackoverflow.com/users/869951/schollii> contributions


On Thu, Sep 8, 2016 at 1:44 PM, oliver <oliver.schoenborn at gmail.com> wrote:

>
> On Thu, Sep 8, 2016 at 1:40 PM, oliver <oliver.schoenborn at gmail.com>
> wrote:
>
>> float pos_x = 33*25*, pos_y = -10;
>
>
> sorry that line should read
>
> float pos_x = -33 * 25, pos_y = -10 * (rand() / float(RAND_MAX
> <http://www.cplusplus.com/RAND_MAX>));
>
> (the randomness along x is not important)
>
> Oliver
> Open Source contributions: PyPubSub <http://pubsub.sf.net/>, nose2pytest
> <https://github.com/schollii/nose2pytest>, Lua-iCxx
> <http://lua-icxx.sf.net/>, iof <http://iof.sf.net/>
> StackOverflow <http://stackoverflow.com/users/869951/schollii>
>  contributions
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20160908/63408a98/attachment.html>


More information about the PyQt mailing list