[Moved] How to QGraphicsView receive keyPressEvent to active a QState



  • in a QGraphicsView ,when a new key pressed ,how to connect this event to make QState jump from state1 to state2

    i write a transition, crashed when begin to run :

    DllMain DLL_PROCESS_DETACH
    E:\Qt4test\AnimateHead-build-desktop\debug\AnimateHead.exe exited with code -1073741819

    @class KeyPressTransition: public QSignalTransition
    {
    public:
    KeyPressTransition(View *receiver, Qt::Key key)
    : QSignalTransition(receiver, SIGNAL(keyPressed(int))), m_key(key)
    {
    }

    KeyPressTransition(View *receiver, Qt::Key key, QAbstractState *target)
        : QSignalTransition(receiver, SIGNAL(keyPressed(int))), m_key(key)
    {
        setTargetState(target);
    }
    
    virtual bool eventTest(QEvent *e)
    {
        if (QSignalTransition::eventTest(e)) {
            QVariant key = static_cast<QStateMachine::SignalEvent*>(e)->arguments().at(0);
            return (key.toInt() == int(m_key));
        }
    
        return false;
    }
    

    private:
    Qt::Key m_key;
    };

    KeyPressTransition *t1=new KeyPressTransition(view,Qt::Key_Right,Rightstate1);
    InitialState->addTransition(t1);

    t1->addAnimation(new QPropertyAnimation(BiglocalItem, "pos"));
    t1->addAnimation(new QPropertyAnimation(BigonlineItem, "pos"));
    t1->addAnimation(new QPropertyAnimation(BigdownloadItem, "pos"));
    t1->addAnimation(new QPropertyAnimation(BigneighborItem, "pos"));
    t1->addAnimation(new QPropertyAnimation(BigsettingItem, "pos"));
    
    t1->addAnimation(new QPropertyAnimation(BiglocalItem, "scale"));
    t1->addAnimation(new QPropertyAnimation(BigonlineItem, "scale"));
    t1->addAnimation(new QPropertyAnimation(BigdownloadItem, "scale"));
    t1->addAnimation(new QPropertyAnimation(BigneighborItem, "scale"));
    t1->addAnimation(new QPropertyAnimation(BigsettingItem, "scale"));@


  • Hello,

    Just a remark : on your QSignalTransition constructor, you give a "receiver" as first parameter. It should be the sender (http://doc.qt.nokia.com/4.6/qsignaltransition.html#QSignalTransition-2), isn't it?



  • This really isn't the correct forum for these questions: "The purpose of this forum":http://developer.qt.nokia.com/forums/viewthread/264/


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.