GraphicsView rotate problem
I currently have an image displayed in the graphics view with the following function:
Code:
void Form::setImage(std::string filename)
{
image
= image.
transformed(QMatrix().
rotate(-90), Qt
::FastTransformation);
ui.graphicsView->setBackgroundBrush(image);
}
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:
Code:
void Form::scaleView(qreal scaleFactor)
{
qreal scale = pow(2.0, (scaleFactor) );
matrix.scale(scale, scale);
matrix.rotate(levelRotate);
ui.graphicsView->setMatrix(matrix);
}
Re: GraphicsView rotate problem
Could you provide a minimal compilable example which reproduces the problem?
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.
Re: GraphicsView rotate problem
Isn't that the same problem as in this thread?
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.
Re: GraphicsView rotate problem
Quote:
Originally Posted by
forrestfsu
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
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()?
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:
Code:
{
// Setup scene
scene->setSceneRect(0,0,512,640);
scene->setItemIndexMethod(QGraphics::NoIndex);
scene->setBackgroundBrush(Qt::black);
// Add pixmap to scene
scene->addPixmap(image);
// Display image on graphicsView
ui.graphicsView->setScene(&*scene);
ui.graphicsView->viewport()->repaint();
}
Re: GraphicsView rotate problem
Exactly the problem I was having, and a nice solution. THANKS!
bjh