Results 1 to 8 of 8

Thread: GraphicsView rotate problem

  1. #1
    Join Date
    Oct 2006
    Posts
    83
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default GraphicsView rotate problem

    I currently have an image displayed in the graphics view with the following function:
    Qt Code:
    1. void Form::setImage(std::string filename)
    2. {
    3. QPixmap image(filename.c_str());
    4. image = image.transformed(QMatrix().rotate(-90), Qt::FastTransformation);
    5. ui.graphicsView->setBackgroundBrush(image);
    6. }
    To copy to clipboard, switch view to plain text mode 

    That seems to work fine (it takes the original image and rotates it 90 degrees cclockwise). So here's the problem, when I use the following function, to rotate the image further, it rotates the image but leaves the original image in the background. I went through the 40000 chips example, and I don't necessarily see anything different with my code. If anyone knows why the original image is shown beneath the rotation, please let me know. Here is the function:
    Qt Code:
    1. void Form::scaleView(qreal scaleFactor)
    2. {
    3. qreal scale = pow(2.0, (scaleFactor) );
    4. QMatrix matrix;
    5. matrix.scale(scale, scale);
    6. matrix.rotate(levelRotate);
    7. ui.graphicsView->setMatrix(matrix);
    8. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: GraphicsView rotate problem

    Could you provide a minimal compilable example which reproduces the problem?

  3. #3
    Join Date
    Oct 2006
    Posts
    83
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: GraphicsView rotate problem

    I'll go ahead and try to put something together. In the meantime this is what it looks like when I add the original image:
    _________
    |######|
    |######|
    |######|
    |######|

    Then After the rotate it looks like this:
    _________
    |##/#\ #|
    |#/###\ |
    |/### /#|
    |#\ #/##|

    I want it to look like this:
    _________
    | /# \ |
    | /### \ |
    |/### / |
    |\## / |

    Sorry for the garbage diagrams, its just that my development box is not on the internet and its a pain to transfer data between the two.
    Last edited by forrestfsu; 16th October 2006 at 21:44.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: GraphicsView rotate problem

    Isn't that the same problem as in this thread?

  5. #5
    Join Date
    Oct 2006
    Posts
    83
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: GraphicsView rotate problem

    No, that thread was about setting a forms background to a specific image. The problem (in that thread) was that it would tile the image on the background, which was not the desired effect.

    In regards to this thread, I have a form, which has a graphics view within it. When I add an image to the graphics view scene, it looks perfect. However, if I rotate the graphics view, it displays the image rotate, but tiled. I want it to only show the image rotated, without tiling.

    I hope this clears it up.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: GraphicsView rotate problem

    Quote Originally Posted by forrestfsu View Post
    No, that thread was about setting a forms background to a specific image.
    Maybe, but QBrush is involved in both cases.

    Quote Originally Posted by forrestfsu View Post
    However, if I rotate the graphics view, it displays the image rotate, but tiled.
    Are you sure there is no tiling before the rotation? Maybe you have to reimplement QGraphicsScene::drawBackground()?

  7. #7
    Join Date
    Oct 2006
    Posts
    83
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: GraphicsView rotate problem

    Thanks everyone! Jacek, when you said that it might be tiled prior to the rotation you got me thinking. You were right....I was using "setBackgroundBrush(image)"...and it seems that by default that tiles the image across the background. I figured out a way to get my code to work, and here it is if anybody ever has a similar problem:

    Qt Code:
    1. void Form::setImage(QPixmap image)
    2. {
    3. // Setup scene
    4. scene = new QGraphicsScene;
    5. scene->setSceneRect(0,0,512,640);
    6. scene->setItemIndexMethod(QGraphics::NoIndex);
    7. scene->setBackgroundBrush(Qt::black);
    8. // Add pixmap to scene
    9. scene->addPixmap(image);
    10. // Display image on graphicsView
    11. ui.graphicsView->setScene(&*scene);
    12. ui.graphicsView->viewport()->repaint();
    13. }
    To copy to clipboard, switch view to plain text mode 

  8. The following user says thank you to forrestfsu for this useful post:

    bjh (21st November 2007)

  9. #8
    Join Date
    Sep 2007
    Posts
    14
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: GraphicsView rotate problem

    Exactly the problem I was having, and a nice solution. THANKS!


    bjh

Similar Threads

  1. Grid Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2006, 12:45
  2. Problem with bitBlt
    By yellowmat in forum Newbie
    Replies: 1
    Last Post: 5th April 2006, 14:08
  3. fftw problem
    By lordy in forum General Programming
    Replies: 1
    Last Post: 16th March 2006, 21:36
  4. Replies: 16
    Last Post: 7th March 2006, 15:57
  5. QPainter rotate function
    By ir210 in forum Newbie
    Replies: 3
    Last Post: 17th January 2006, 04:31

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.