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. Adding action to an event

Adding action to an event

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 640 Views
  • 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.
  • U Offline
    U Offline
    umadevi
    wrote on last edited by
    #1

    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.

    RatzzR 1 Reply Last reply
    0
    • U umadevi

      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.

      RatzzR Offline
      RatzzR Offline
      Ratzz
      wrote on last edited by
      #2

      @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

      --Alles ist gut.

      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