I've created 4 different QState and i want to hide one object in evry state transition.
This is the code:
QStateMachine partita;
QState *inizio_mano = new QState();
QState *aspetto_G1_primo = new QState();
QState *aspetto_G1_secondo = new QState();
QFinalState *fine_mano = new QFinalState();
partita.setInitialState(inizio_mano);
inizio_mano -> addTransition(this,presa==true,aspetto_G1_primo);
inizio_mano -> addTransition(this,presa==false,aspetto_G1_secondo);
aspetto_G1_primo -> addTransition(this,stato==true,fine_mano);
aspetto_G1_secondo -> addTransition(this,stato==true,fine_mano);
presa
and stato
are two bool
I change in the next step of program.
Now I have a QGraphicsScene
and in the scene I've added in it some QGraphicsPixmapItem
.
For example I want to update the scene hiding an item:
if(presa==true) {object1->hide();}
I understand I have to change the QState (in this case from inizio_mano
to aspetto_G1_primo
), and I've done it adding a transition.
But how I can hide that Item ?
How can I connect the QState aspetto_G1_primo
with object1 -> hide();
I hope I explained correctly.
My main problem is: how do I assign to each QState a different configuration of the scene ?
You have all the properties of a QWidget
here: http://doc.qt.io/qt-5/qwidget.html#properties
Each child class also have their own additional properties, which are in the doc.
So you can do :
aspetto_G1_primo->assignProperty(object1, "visible", false);
Then when entering that state the property "visible" of object1
will be set to false
.
You can also do the same to edit any other property depending on the state, such as the geometry, the stylesheet, or the text of labels...