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. Ignore standard input
Forum Updated to NodeBB v4.3 + New Features

Ignore standard input

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 439 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.
  • G Offline
    G Offline
    gabello306
    wrote on last edited by
    #1

    I am new to Qt and am trying to replace a character in an input into a QLineEdit field. I have created a QKeyPressed method to get each character.

    //-----------------------------------------------------------------------------
    // eventFilter
    // Evaluate each character input
    //-----------------------------------------------------------------------------
    bool NotebookView::eventFilter(QObject* watched, QEvent* event)
    {
        if(watched->inherits("QLineEdit"))
        {
            if(event->type() == QEvent::KeyPress)
            {
                QKeyEvent* keyCode = static_cast<QKeyEvent*>(event);
                if((watched == ui->aoEnterVal) || (watched == ui->aoRangeVal))
                {
                    m_pCommon->AO_Char(watched, keyCode);
                }
            }
        }
        return QObject::eventFilter(watched, event);
    }
    
    I am trying to replace the space with an actual value.
    
    case Qt::Key_Space:
    
        str = control->objectName().toStdString();
    
        // Don't display Preferences character in Remarks
        if( ( str.substr ( 2, 6 ) != "Remark" ) ||
            ( str == "mmEnterVal" ) )
        {
            // Fill character from defined character in Preferences
            editField->insert(Preferences.currChar);
        }
        else
        {
            editField->insert(" ");
        }
        break;
    

    The case works but I am still getting the space in the QLineEdit field. If I replace a character, I need to ignore the actual input character. Any ideas?

    1 Reply Last reply
    0
    • hskoglundH Offline
      hskoglundH Offline
      hskoglund
      wrote on last edited by
      #2

      Hi, instead of passing the torch, i.e. doing
      return QObject::eventFilter(watched, event);
      try
      return true;
      to toss the key.

      1 Reply Last reply
      1
      • G Offline
        G Offline
        gabello306
        wrote on last edited by
        #3

        I tried that and it doesn't even show the QlineEdit entry fields. They are are just gone.

        JonBJ 1 Reply Last reply
        0
        • G gabello306

          I tried that and it doesn't even show the QlineEdit entry fields. They are are just gone.

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @gabello306
          Could you show the code as you have it now? You haven't literally replaced the only return QObject::eventFilter(watched, event); occurrence in your code above with an unconditional return true;, have you?

          1 Reply Last reply
          1
          • G Offline
            G Offline
            gabello306
            wrote on last edited by
            #5

            I figured out the problem. Instead of putting the return true at the end, I added it under the AO_Char call. Doing this gets rid of the extra character. See the code below for the change.

            //-----------------------------------------------------------------------------
            // eventFilter
            // Evaluate each character input
            //-----------------------------------------------------------------------------
            bool NotebookView::eventFilter(QObject* watched, QEvent* event)
            {
                if(watched->inherits("QLineEdit"))
                {
                    if(event->type() == QEvent::KeyPress)
                    {
                        QKeyEvent* keyCode = static_cast<QKeyEvent*>(event);
                        if((watched == ui->aoEnterVal) || (watched == ui->aoRangeVal))
                        {
                            m_pCommon->AO_Char(watched, keyCode);
                            return true;
                        }
                    }
                }
                return QObject::eventFilter(watched, event);
            }
            
            
            1 Reply Last reply
            0
            • G gabello306 has marked this topic as solved on
            • JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #6

              @gabello306 Yes, well done, that is what @hskoglund meant :) You only return true for those events you have handled/want ignored.

              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