Adding action to an event



  • Hello all,

    I have re implemented Key press event to rotate image displayed using QGraphicsview. here is code.

    void CustomView::keyPressEvent(QKeyEvent *event)
    {
    if (event->modifiers().testFlag(Qt::ControlModifier))
    {
    if (event->key() == Qt::Key_C)
    {
    r_angle = r_angle + angle;
    rotate(angle);
    }
    }
    if (event->modifiers().testFlag(Qt::ControlModifier))
    {
    if (event->key() == Qt::Key_A)
    {
    l_angle = l_angle - angle;
    rotate(-(angle));
    }
    }
    if (event->key() == Qt::Key_Space)
    {
    if (r_angle > 0)
    {
    rotate(-(r_angle));
    r_angle = 0;
    }
    if (l_angle < 0)
    {
    rotate(-(l_angle));
    l_angle = 0;
    }
    }
    }

    How to link this to an any action. ? For example if I have action called rotate_image, how to call keypress event so that by clicking rotate_image the image will rotate. Is it possible to do that.



  • @umadevi said in Adding action to an event:

    how to call keypress event

    Keypress events are called when you provide a keyboard input?

    Key events are sent to the widget with keyboard input focus when keys are pressed or released
    http://doc.qt.io/qt-4.8/qkeyevent.html#details


Log in to reply
 

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