Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. [PySide] QGraphicsItemGroup not visible
QtWS25 Last Chance

[PySide] QGraphicsItemGroup not visible

Scheduled Pinned Locked Moved Language Bindings
3 Posts 2 Posters 2.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    the-me
    wrote on last edited by
    #1

    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_())
    @

    1 Reply Last reply
    0
    • jazzycamelJ Offline
      jazzycamelJ Offline
      jazzycamel
      wrote on last edited by
      #2

      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_())
      

      @

      For the avoidance of doubt:

      1. All my code samples (C++ or Python) are tested before posting
      2. As of 23/03/20, my Python code is formatted to PEP-8 standards using black from the PSF (https://github.com/psf/black)
      1 Reply Last reply
      0
      • T Offline
        T Offline
        the-me
        wrote on last edited by
        #3

        Hi,

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

        I'll contact the PySide guys.

        Thanks for your efforts :)

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved