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. [SOLVED] how to capture the ctrl + c in the eventfilter?
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] how to capture the ctrl + c in the eventfilter?

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 6.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
    kalster
    wrote on last edited by
    #1

    i am having problems capturing a Qmenu shortcut in a Qplaintextedit. the problem is when i set the menu item to ctrl + c and click that menu item, nothing happens in the plaintextedit eventfilter. below is the code to try to resolve this issue but nothing happens at all. if i use the short cut of ctrl without the "c" then it works but with the "c" it does not work. help please. thank you in advanced. below is my code.

    @bool MainWindow::eventFilter(QObject *object, QEvent *event)
    {
    if (object == plainTextEdit && event->type() == QEvent::KeyPress)
    {
    QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);

       if (keyEvent->key() == Qt::Key_Control)
        {
            if (keyEvent->key() == Qt::Key_C)
            // do something
            }
        } else
        {
            return QMainWindow::eventFilter(object, event);
        }
    }
    else
    {
        return QMainWindow::eventFilter(object, event);
    }
    

    }@

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      You should try:

      @
      if(keyEvent->key() == Qt::Key_C && keyEvent->modifiers().testFlag(Qt::ControlModifier))
      {
      // eat the ctrl-c which is cmd-c on the mac
      }
      @

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

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kalster
        wrote on last edited by
        #3

        thank you Volker. it works

        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