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. [Solved] Python QPixmap positioning?
Qt 6.11 is out! See what's new in the release blog

[Solved] Python QPixmap positioning?

Scheduled Pinned Locked Moved Language Bindings
4 Posts 2 Posters 7.5k Views 1 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    Hi,

    I'm trying to change the position of a pixmap, but it doesn't seem to be working:

    @iconview = QtGui.QGraphicsView()
    scn = QtGui.QGraphicsScene(iconView)
    scn.setSceneRect(iconView.sceneRect())
    iconView.setScene(scn)
    pix = QtGui.QPixmap("picture.xpm")
    item = QtGui.QGraphicsPixmapItem(scn.addPixmap(pix))
    item.setPos(0, 30) # for ex@

    It displays the picture, but doesn't move the position...just stays in the center.

    Thanks!!

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      Any ideas?

      Thanks!!

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

        Your problem is with the following line:

        @scn.setSceneRect(iconView.sceneRect())@

        If you print out the result of sceneRect() you get:

        @QRectF(0.0, 0.0, 0.0, 0.0)@

        i.e. a rectangle of no size. This is because the QGraphicsView doesn't have a scene from which to get a size yet so returns default. If you set a size as follows your icon will be placed as desired:

        @scn.setSceneRect(QRectF(0.0, 0.0, 250.0, 250.0))@

        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
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          Thanks again, jazzycamel!!! :)

          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