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. PySide2: Filling not scaled
Forum Updated to NodeBB v4.3 + New Features

PySide2: Filling not scaled

Scheduled Pinned Locked Moved Unsolved Language Bindings
pyside2qgraphicsscenescale
3 Posts 2 Posters 783 Views 2 Watching
  • 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.
  • galou_breizhG Offline
    galou_breizhG Offline
    galou_breizh
    wrote on last edited by
    #1

    I tried to draw a circle from real-world units (in my case in meters up to a few meters). I tried to scale my QGraphicsItem element but it appears that the filling is note scaled correctly:

    #!/usr/bin/python3
    # -*- coding: utf-8 -*-
    """Shows an incomprehension (bug?) while scaling a graphics item"""
    
    from PySide2 import QtCore
    from PySide2 import QtGui
    from PySide2 import QtWidgets
    
    point_size = 0.1  # In real-world units.
    
    # Get entrypoint through which we control underlying Qt framework
    app = QtWidgets.QApplication([])
    
    scene = QtWidgets.QGraphicsScene()
    scale = 500  # 1 real-world units = 500 px.
    pen = QtGui.QPen(QtCore.Qt.red)
    brush = QtGui.QBrush(QtCore.Qt.blue)
    x = 1  # Real-world units.
    y = 2  # Real-world units.
    top_left = (x - point_size / 2, y - point_size / 2)
    ellipse = QtWidgets.QGraphicsEllipseItem(
        QtCore.QRectF(*top_left, point_size, point_size))
    ellipse.setPen(pen)
    ellipse.setBrush(brush)
    ellipse.setScale(scale)
    scene.addItem(ellipse)
    
    view = QtWidgets.QGraphicsView(scene)
    view.show()
    
    # Start Qt/PySide2 application. If we don't show any windows, the
    # app would just loop at this point without the means to exit
    app.exec_()
    
    

    What I get is something between a circle and a square with red stroke (size 500x500 px²) filled with white color with a 50x50 px² blue circle in the middle.
    Cf. screenshot

    Thanks for any help on this!
    Gaël

    1 Reply Last reply
    0
    • galou_breizhG Offline
      galou_breizhG Offline
      galou_breizh
      wrote on last edited by
      #2

      The problem appears rather to be that the stroke is wrongly scaled. The filling has the correct size. There must be some round error somewhere that screw up the scaling of the stroke.

      Gojir4G 1 Reply Last reply
      0
      • galou_breizhG galou_breizh

        The problem appears rather to be that the stroke is wrongly scaled. The filling has the correct size. There must be some round error somewhere that screw up the scaling of the stroke.

        Gojir4G Offline
        Gojir4G Offline
        Gojir4
        wrote on last edited by Gojir4
        #3

        @galou_breizh
        I think point_size is too small and the ellipse generated is "pixelated" because of that.

        This gives a nice circle filled with blue

        # -*- coding: utf-8 -*-
        """Show an incomprehension in setScale for QGraphicsItemGroup."""
        
        from PySide2 import QtCore
        from PySide2 import QtGui
        from PySide2 import QtWidgets
        
        point_size = 10.0  # In real-world units.
        
        # Get entrypoint through which we control underlying Qt framework
        app = QtWidgets.QApplication([])
        
        scene = QtWidgets.QGraphicsScene()
        group = QtWidgets.QGraphicsItemGroup()
        
        scale = 50.0  # 1 real-world units = 500 px.  !! Has no apparent effect.
        
        pen = QtGui.QPen(QtCore.Qt.red)
        brush = QtGui.QBrush(QtCore.Qt.blue)
        x = 1.0  # Real-world units.
        y = 2.0  # Real-world units.
        top_left = (x - point_size / 2.0, y - point_size / 2.0)
        
        ellipse = QtWidgets.QGraphicsEllipseItem(
            QtCore.QRectF(*top_left, point_size, point_size))
        ellipse.setPen(pen)
        ellipse.setBrush(brush)
        ellipse.setScale(scale)
        group.addToGroup(ellipse)
        # group.setScale(scale)
        scene.addItem(group)
        
        view = QtWidgets.QGraphicsView(scene)
        view.show()
        
        # Start Qt/PySide2 application. If we don't show any windows, the
        # app would just loop at this point without the means to exit
        app.exec_()
        
        1 Reply Last reply
        2

        • Login

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