tags:

views:

101

answers:

1

I need to view QGraphicsScene in 2 QGraphicsViews with condition that they have different scale factors for items in scene. Closest function which I found is drawItems(), but as far I can understand, it must be called manually. How to repaint views automatically? I have these two code fragments in program:

class TGraphicsView(QGraphicsView):

    def __init__(self, parent = None):
        print("__init__")
        QGraphicsView.__init__(self, parent)

    def drawItems(self, Painter, ItemCount, Items, StyleOptions):
        print("drawItems")
        Brush = QBrush(Qt.red, Qt.SolidPattern)
        Painter.setBrush(Brush)
        Painter.drawEllipse(0, 0, 100, 100)

...

    Mw.gvNavigation = TGraphicsView(Mw) # Mw - main window
    Mw.gvNavigation.setGeometry(0, 0, Size1, Size1)
    Mw.gvNavigation.setScene(Mw.Scene)
    Mw.gvNavigation.setSceneRect(0, 0, Size2, Size2)
    Mw.gvNavigation.show()

_init_ works, Mw.gvNavigation is displayed and there are Mw.Scene items in it, but drawItems() isn't called.

+1  A: 

The drawItems methods on QGraphicsView and QGraphicsScene objects have been deprecated in Qt 4.6 and have to be enabled using the IndirectPainting flag, but I would't recommend using deprecated features.

Here's another stack overflow question on a similar issue. One of the answers shows how to make the paint methods on individual items in a scene aware of which view is painting them, and use different paint code when drawn in different views.

Simon Hibbs