August 30, 2010

kingnight kingnight
Lab Rat
1 posts

[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

  1. class KeyPressTransition: public QSignalTransition
  2. {
  3. public:
  4.     KeyPressTransition(View *receiver, Qt::Key key)
  5.         : QSignalTransition(receiver, SIGNAL(keyPressed(int))), m_key(key)
  6.     {
  7.     }
  8.  
  9.     KeyPressTransition(View *receiver, Qt::Key key, QAbstractState *target)
  10.         : QSignalTransition(receiver, SIGNAL(keyPressed(int))), m_key(key)
  11.     {
  12.         setTargetState(target);
  13.     }
  14.  
  15.     virtual bool eventTest(QEvent *e)
  16.     {
  17.         if (QSignalTransition::eventTest(e)) {
  18.             QVariant key = static_cast<QStateMachine::SignalEvent*>(e)->arguments().at(0);
  19.             return (key.toInt() == int(m_key));
  20.         }
  21.  
  22.         return false;
  23.     }
  24. private:
  25.     Qt::Key m_key;
  26. };
  27.  
  28. KeyPressTransition *t1=new KeyPressTransition(view,Qt::Key_Right,Rightstate1);
  29. InitialState->addTransition(t1);
  30.  
  31.     t1->addAnimation(new QPropertyAnimation(BiglocalItem, "pos"));
  32.     t1->addAnimation(new QPropertyAnimation(BigonlineItem, "pos"));
  33.     t1->addAnimation(new QPropertyAnimation(BigdownloadItem, "pos"));
  34.     t1->addAnimation(new QPropertyAnimation(BigneighborItem, "pos"));
  35.     t1->addAnimation(new QPropertyAnimation(BigsettingItem, "pos"));
  36.  
  37.     t1->addAnimation(new QPropertyAnimation(BiglocalItem, "scale"));
  38.     t1->addAnimation(new QPropertyAnimation(BigonlineItem, "scale"));
  39.     t1->addAnimation(new QPropertyAnimation(BigdownloadItem, "scale"));
  40.     t1->addAnimation(new QPropertyAnimation(BigneighborItem, "scale"));
  41.     t1->addAnimation(new QPropertyAnimation(BigsettingItem, "scale"));

2 replies

August 30, 2010

ngrosjean ngrosjean
Lab Rat
35 posts

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?

August 30, 2010

Franzk Franzk
Lab Rat
837 posts

This really isn’t the correct forum for these questions: The purpose of this forum [developer.qt.nokia.com]

 Signature 

“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

 
  ‹‹ align icon on a tab (QTabWidget) & tab widths      Translating application menu on Mac ››

You must log in to post a reply. Not a member yet? Register here!