Error creating a animated menu
Hi,
I'm trying create a animated menu, i'ts a simple animation, just show and hide the menu.
But I get a error and can't figure that out
Code:
Menu *menu = new Menu();
menu->setPos(0, scene->sceneRect().center().y() - (menu->boundingRect().center().y()*scaleT));
scene->addItem(menu);
setScene(scene);
j->setPos(350,0);
i->setPos(400,0);
//animaçao menu
QStateMachine machine;
QState *state_hide = new QState(&machine);
QState *state_show = new QState(&machine);
machine.setInitialState(state_show);
state_show
->assignProperty
(menu,
"pos",
QPointF(110,
200));
state_hide
->assignProperty
(menu,
"pos",
QPointF(800,
200));
QAbstractTransition *t1 = state_show->addTransition(button, SIGNAL(clicked()),state_hide);
QSequentialAnimationGroup *animation1SubGroup = new QSequentialAnimationGroup;
animation1SubGroup->addPause(250);
t1->addAnimation(animation1SubGroup);
t1->addAnimation(new QPropertyAnimation(menu, "pos"));
QAbstractTransition *t2 = state_hide->addTransition(button, SIGNAL(clicked()), state_show);
t2->addAnimation(new QPropertyAnimation(menu, "pos"));
machine.start();
Code:
{
public:
Menu();
protected:
private:
};
Code:
Menu::Menu()
{
visible = false;
menu_image
= new QImage("C:/menu.png");
setRect(0, 0, menu_image->width(), menu_image->height());
setFlag(ItemIsMovable);
float itemScale
= (float) QApplication::desktop()->width
() / (float)1920;
this->setScale(itemScale);
Botao
*button1
= new Botao
(QImage("C:/botao.png"),
QImage("C:/botao2.png"),
"Iluminação Terreo");
button1->setParentItem(this);
button1->setPos(0,226);
}
Errors:
Quote:
mainview.cpp:67: error: no matching function for call to 'QState::assignProperty(Menu*&, const char [4], QPointF)'
../src/corelib/statemachine/qstate.h:94: note: candidates are: void QState::assignProperty(QObject*, const char*, const QVariant&)
mainview.cpp:69: error: no matching function for call to 'QState::assignProperty(Menu*&, const char [4], QPointF)'
../src/corelib/statemachine/qstate.h:94: note: candidates are: void QState::assignProperty(QObject*, const char*, const QVariant&)
mainview.cpp:76: error: no matching function for call to 'QPropertyAnimation::QPropertyAnimation(Menu*&, const char [4])'
../src/corelib/animation/qpropertyanimation.h:79: note: candidates are: QPropertyAnimation::QPropertyAnimation(const QPropertyAnimation&)
../src/corelib/animation/qpropertyanimation.h:64: note: QPropertyAnimation::QPropertyAnimation(QObject*, const QByteArray&, QObject*)
../src/corelib/animation/qpropertyanimation.h:63: note: QPropertyAnimation::QPropertyAnimation(QObject*)
mainview.cpp:79: error: no matching function for call to 'QPropertyAnimation::QPropertyAnimation(Menu*&, const char [4])'
../src/corelib/animation/qpropertyanimation.h:79: note: candidates are: QPropertyAnimation::QPropertyAnimation(const QPropertyAnimation&)
../src/corelib/animation/qpropertyanimation.h:64: note: QPropertyAnimation::QPropertyAnimation(QObject*, const QByteArray&, QObject*)
../src/corelib/animation/qpropertyanimation.h:63: note: QPropertyAnimation::QPropertyAnimation(QObject*)
Re: Error creating a animated menu
Re: Error creating a animated menu
Thanks for answer.
I just add the QObject in the class:
class Menu: public QObject, public QGraphicsRectItem
Now compile with no errors, but doesn't work.
The menu stay in the same position.
Re: Error creating a animated menu
Why would anything change position? Did you read the animation framework docs before trying to use it?