[PySide] QGraphicsItemGroup not visible



  • Hi all,
    I'm a long time Pythonista, but a freshman when it comes to Qt. And now I have this little issue :) . I want do display a compass rose, basically, and group that thing into a QGraphicsItemGroup. And it does not work. Adding the lines to the scene works just fine, but as soon as I replace the discrete lines with a QGIG, the opening window stays empty. Switching line 24/25 in the 2nd example makes no difference btw. The code is below. Can anybody help me maybe?

    WORKING:

    @def fill_group_with_full_rose_compass(scene, size=400):
    def do_lines(length, delta, no_line, pen):
    for angle in [ldelta for l in range(360/delta)]:
    if angle in no_line:
    continue
    line = QGraphicsLineItem(size/2,0, size/2,length)
    line.setTransformOriginPoint(size/2, size/2)
    line.setRotation(angle)
    line.setPen(pen)
    scene.addItem(line)
    pen = QPen(Qt.black, size/200, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)
    do_lines(size/8, 30, [], pen)
    pen = QPen(Qt.black, size/400, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)
    do_lines(size/12, 10, [a
    30 for a in range(12)], pen)
    pen = QPen(Qt.black, size/400, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)
    do_lines(size/20, 5, [a*10 for a in range(36)], pen)

    if name == 'main':
    app = QApplication(sys.argv)
    scene = QGraphicsScene()

    fill_group_with_full_rose_compass(scene, 400)

    continued .......@

    NO LONGER WORKING:

    @def fill_group_with_full_rose_compass(group, size=400):
    def do_lines(length, delta, no_line, pen):
    for angle in [ldelta for l in range(360/delta)]:
    if angle in no_line:
    continue
    line = QGraphicsLineItem(size/2,0, size/2,length)
    line.setTransformOriginPoint(size/2, size/2)
    line.setRotation(angle)
    line.setPen(pen)
    group.addToGroup(line)
    #group.addItem(line)
    pen = QPen(Qt.black, size/200, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)
    do_lines(size/8, 30, [], pen)
    pen = QPen(Qt.black, size/400, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)
    do_lines(size/12, 10, [a
    30 for a in range(12)], pen)
    pen = QPen(Qt.black, size/400, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)
    do_lines(size/20, 5, [a*10 for a in range(36)], pen)

    if name == 'main':
    app = QApplication(sys.argv)
    scene = QGraphicsScene()

    compass = QGraphicsItemGroup()
    fill_group_with_full_rose_compass(compass, 400)
    scene.addItem(compass)

    continued ...

    view = QGraphicsView(scene)
    view.setRenderHints(QPainter.Antialiasing or QPainter.SmoothPixmapTransform)
    if NO_INDEX:
    view.setItemIndexMethod(QGraphicsScene.NoIndex);
    if OPTIMIZE:
    view.setOptimizationFlags(QGraphicsView.DontAdjustForAntialiasing
    or QGraphicsView.DontClipPainter
    or QGraphicsView.DontSavePainterState)

    view.show()
    sys.exit(app.exec_())
    @



  • Hi,
    I've run your code (with some very minor changes, see below) and both cases work fine for me. What OS, Python, Qt and PyQt versions are you using? My setup is as follows:

    Mac OSX Lion
    Python 2.7.1
    Qt 4.8.1
    PyQt 4.9.4

    EDIT: My bad, I just realised your using PySide rather than PyQt. Seeing as it works fine in PyQt however I would tentatively suggest its a PySide issue (I don't have PySide installed so I'm afraid I can't confirm this).

    @
    from PyQt4.QtCore import *
    from PyQt4.QtGui import *

    def fill_group_with_full_rose_compass(group, size=400):
    def do_lines(length, delta, no_line, pen):
    for angle in [l*delta for l in range(360/delta)]:
    if angle in no_line: continue

            line = QGraphicsLineItem(size/2,0, size/2,length)
            line.setTransformOriginPoint(size/2, size/2)
            line.setRotation(angle)
            line.setPen(pen)
            group.addToGroup(line)
    
    pen = QPen(Qt.black, size/200, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)
    do_lines(size/8, 30, [], pen)
    pen = QPen(Qt.black, size/400, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)
    do_lines(size/12, 10, [a*30 for a in range(12)], pen)
    pen = QPen(Qt.black, size/400, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)
    do_lines(size/20, 5, [a*10 for a in range(36)], pen)
    

    if name == 'main':
    from sys import argv, exit

    app = QApplication(argv)
    scene = QGraphicsScene()
    
    compass=QGraphicsItemGroup()
    fill_group_with_full_rose_compass(compass, 400)
    scene.addItem(compass)
    
    view=QGraphicsView(scene)
    view.setRenderHints(QPainter.Antialiasing | QPainter.SmoothPixmapTransform)
    
    scene.setItemIndexMethod(QGraphicsScene.NoIndex)
    view.setOptimizationFlags(QGraphicsView.DontAdjustForAntialiasing | QGraphicsView.DontClipPainter | QGraphicsView.DontSavePainterState)
    
    view.show()
    
    exit(app.exec_())
    

    @



  • Hi,

    I can confirm it :) . Your code does not work here with PySide. Shame.

    I'll contact the PySide guys.

    Thanks for your efforts :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.