Important: Please read the Qt Code of Conduct -

QGraphicsView and wrap around?

  • I'm using Python 2.7 and PyQt.

    Let's say I have a QGraphicsScene and a QGraphicsView and I want to draw simple Ellipses. I want them to wrap around: when I draw a ellipse centered at upper-lef corner of the visible view area, it should be visible in all four corners: a quarter sector in each.

    How to accomplish this with PyQt?

  • Wrap around as such doesn't exist in graphicsview. The canvas is of infinite size and the view just provides a small view on that.

    What you might want to do is auto create duplicates of your ellipse and position them at offsets equal to the viewport size.

  • If you render to a "buffer" it can be implemented fairly easy. Basically you have a 2D image and a 2D offset which divides the image into 4 portions. Then you use those 4 portions to render the offset image. I guess you could do that by subclassing QGraphicsView and reimplementing some functionality, but you will probably have to do it in C++.

  • I'm very new to PyQt. This would be very easy if I could just draw individual pixels to offscreen buffer and copy it constantly to visible window. But I have no idea how to do it with PyQt.

    Any pointers? Ie.

    1. How to open an offscreen buffer of size widthxheight.
    2. How to draw a pixel to the bugffer?
    3. How to copy it to screen?

    I'm used to doing all by hand :)

    But if the above is not easy, I'll simply use 4 different ellipses when needed. And delete them when there is no wrapping condition.

  • If it is possible to solve your problem with instancing and symmetry along x and y it would probably be easier, more math, less code.

    Or you can use even a basic widget to draw with QPainter, convert the widget to a QPixmap of the widget's size(), logically divide the pixmap into 4 parts and use resulting QRect's to reconstruct the final image in another pixmap and display it.


Log in to reply