Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Moved] How to QGraphicsView receive keyPressEvent to active a QState
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 3.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kingnight
    wrote on last edited by
    #1

    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"));@
    
    1 Reply Last reply
    0
    • N Offline
      N Offline
      ngrosjean
      wrote on last edited by
      #2

      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?

      1 Reply Last reply
      0
      • F Offline
        F Offline
        Franzk
        wrote on last edited by
        #3

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

        "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

        http://www.catb.org/~esr/faqs/smart-questions.html

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved