Reference QGraphicsPixmapItem without adding it
What I want to happen is this. When a certain key is pressed.
QPixmap image ("path");
QGraphicsPixmapItem *pixmap = addPixmap(image);
pixmap->setRotation(x);
This works as it is but every time a key is pressed instead of rotating the current image it adds a new one rotated. So i need to be able to declare what pixmap is without adding it. I think I just need to change this line.
QGraphicsPixmapItem *pixmap = addPixmap(image);
And I could initialialy add it somewhere else.
Here is a portion of my current code.
void Scene::keyPressEvent( QKeyEvent *e )
{
QPixmap image ("path");
QGraphicsPixmapItem *pixmap = addPixmap(image);
switch ( e->key() )
{
case Qt::Key_Left:
{
pixmap->setRotation(x);
break;
}
Re: Reference QGraphicsPixmapItem without adding it
Create the pixmap item in your constructor and store the pointer to it you a private member variable. Then you can easily access it.
Code:
class Scene : /*...*/
{
//...
private:
}
Scene::Scene(/*...*/) : /*...*/
{
pixmap
= addPixmap
(QPixmap("path"));
}
{
switch ( e->key() )
{
case Qt::Key_Left:
{
m_pixmap->setRotation(x);
break;
}
Re: Reference QGraphicsPixmapItem without adding it
Thanks a lot you're awesome. I knew it had to be something that simple but I just couldn't think of it.