Results 1 to 3 of 3

Thread: Creating a new QPixmap out of a rotated QGraphicsPixmapItem

  1. #1
    Join Date
    Mar 2010
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Creating a new QPixmap out of a rotated QGraphicsPixmapItem

    Hi all,

    I have set up a QGraphicsScene & QGraphicsView and added a QGraphicsPixmapItem that has a square bounding QRect. The center of the QPixmap is at the scene center.
    i.e.

    Qt Code:
    1. QGraphicsView* graphicsView;
    2. QGraphicsScene* graphicsScene = new QGraphicsScene();
    3. QPixmap pic = QPixmap(":/new/pic.jpg").scaled(QSize(100,100));
    4. QGraphicsPixmapItem* bg = graphicsScene->addPixmap(pic);
    5. bg->setPos(-50,-50);
    6. graphicsView->setScene(graphicsScene);
    7. graphicsView->fitInView(bg);
    To copy to clipboard, switch view to plain text mode 

    This allows the pixmap to fill the entire view so I don't see any whitespace. The problem comes when I rotate by calling rotate() on the QGraphicsView which contains pixmap;

    Qt Code:
    1. int degrees;
    2. graphicsView->rotate(degrees);
    To copy to clipboard, switch view to plain text mode 

    Where degrees is some value I get from the user.

    The view rotates as I would expect, creating a "diamond" from the rotated square QPixmap. What I would like to do now is to make a square again by essentially taking the inset square of the image, and filling the graphicsScene with that new image.


    I appreciate any ideas anyone has for how to do this.
    Thank you.
    Last edited by Aondiar; 15th March 2010 at 05:09.

  2. #2
    Join Date
    Feb 2010
    Posts
    96
    Thanks
    4
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Creating a new QPixmap out of a rotated QGraphicsPixmapItem

    I code in Python, FYI. I would recommend creating brand new classes that are subclasses of the Scene and Item objects you need. This will allow you to create brand new instances of the objects. Something like this in python looks like:

    Qt Code:
    1. class MyGraphicsScene(QtGui.QGraphicsScene)
    2. def __init__(self, parent):
    3. super(MyGraphicsScene, self).__init__()
    To copy to clipboard, switch view to plain text mode 
    ..and..
    Qt Code:
    1. class MyGraphicsItem(QtGui.QGraphicsPixmapItem)
    2. def __init__(self, parent):
    3. super(MyGraphicsItem, self).__init__()
    To copy to clipboard, switch view to plain text mode 

    Then the object is itself a class, and an object, GraphicsScene or PixmapItem, allowing you call it, create a second instance of it easly, and even add functions inside it so you can call those.

    I know you are not coding in PyQt, but I thought it would help.

  3. #3
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Creating a new QPixmap out of a rotated QGraphicsPixmapItem

    You could also use
    Qt Code:
    1. bg->setFlags(bg->flags() | QGraphicsItem::ItemIgnoresTransformations );
    To copy to clipboard, switch view to plain text mode 
    Hope that is what you need

Similar Threads

  1. QGraphicsTextItem sharpness when rotated
    By martinn in forum Qt Programming
    Replies: 3
    Last Post: 26th February 2010, 12:13
  2. drawing series of rotated ellipses
    By qtn00b in forum Newbie
    Replies: 1
    Last Post: 17th December 2009, 01:51
  3. How draw a rotated text in a QPainterPath?
    By iw2nhl in forum Qt Programming
    Replies: 6
    Last Post: 17th August 2007, 18:55
  4. Replies: 2
    Last Post: 3rd November 2006, 22:20
  5. rotated labels
    By jayw710 in forum Qt Programming
    Replies: 2
    Last Post: 11th April 2006, 17:47

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.