Results 1 to 8 of 8

Thread: How to get size of pixmap in qgraphicsitem?

  1. #1
    Join Date
    Mar 2014
    Posts
    7
    Thanks
    2
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Question How to get size of pixmap in qgraphicsitem?

    Hi,

    I need to paint a red "X" over the image. For that I must get the size of the black rectangle on the screen but I could only get the size of the blue rectangle.
    I tried using boundingRect(), viewport(), childrenRect() or similar but none of these worked.

    program.jpg

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to get size of pixmap in qgraphicsitem?

    How is the image painted?
    Is it its own graphics item?
    Is it drawn as part of a larger item?

    Cheers,
    _

  3. #3
    Join Date
    Mar 2014
    Posts
    7
    Thanks
    2
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to get size of pixmap in qgraphicsitem?

    There is a single QGraphicsPixmapItem in the scene with the pixmap of the head. On top of the view there is a transparent widget where I paint the red X.

    Scene[0] -> GraphicsView1 -> Item[0] -> Pixmap (Head)
    ----------------------------> Overlay (X)

    This pixmap is painted with scanLine and the red X with QPainter using the screen coordinates. The problem is that I couldn't get the right coordinates.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to get size of pixmap in qgraphicsitem?

    Is the blue area part of the image or the view's background?

    Do you need this to be in an overlay window or could you do it in the graphics scene?
    Have you considered making the X a part of the image drawing?

    Cheers,
    _

  5. #5
    Join Date
    Mar 2014
    Posts
    7
    Thanks
    2
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to get size of pixmap in qgraphicsitem?

    The blue area is the view's background. The problem with painting the X on the scene is that the view can have many items, one on top of the other. But still I need the X to be on top of everything.

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to get size of pixmap in qgraphicsitem?

    How about QGraphicsScene::drawForeground()?

    Cheers,
    _

  7. The following user says thank you to anda_skoa for this useful post:

    darktorres (24th July 2014)

  8. #7
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to get size of pixmap in qgraphicsitem?

    What did you do with boundingRect() of the pixmap item that did not work? Post a code snippet or two.

  9. #8
    Join Date
    Mar 2014
    Posts
    7
    Thanks
    2
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to get size of pixmap in qgraphicsitem?

    I tried drawForeground() and it worked great! Thanks!

Similar Threads

  1. size of pixmap in tableview
    By Cremers in forum Newbie
    Replies: 4
    Last Post: 1st October 2013, 08:10
  2. Qt: How to set the size of Pixmap?
    By sonulohani in forum Qt Programming
    Replies: 2
    Last Post: 5th June 2012, 06:37
  3. Change the size of pixmap in a label
    By metRo_ in forum Qt Programming
    Replies: 16
    Last Post: 1st June 2012, 11:21
  4. Replies: 0
    Last Post: 7th January 2010, 23:03
  5. Drag pixmap on Windows size problem
    By plamkata in forum Qt Programming
    Replies: 1
    Last Post: 20th March 2009, 00:01

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.