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 get the KeyPressEvent for . (Dot) key ?
Forum Updated to NodeBB v4.3 + New Features

[Solved] How to get the KeyPressEvent for . (Dot) key ?

Scheduled Pinned Locked Moved General and Desktop
9 Posts 4 Posters 9.8k 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.
  • M Offline
    M Offline
    Macro
    wrote on last edited by
    #1

    Hi...

    I have a QLineEdit in that if I enter a . (Dot), That . (Dot Value) should be changed to " (Quote symbol) in the Line Edit.

    I Tried using the Qt::Key_Period for getting the . (Dot value). But its not working for me. Plz suggest me how to change the LineEdit Value from .(Dot) to "(Quote) .

    Thanks & Regards.

    1 Reply Last reply
    0
    • H Offline
      H Offline
      hpollak
      wrote on last edited by
      #2

      I think you should work with keyPressEvent

      See "doc":http://qt-project.org/doc/qt-5.0/qtwidgets/qlineedit.html#keyPressEvent for more information.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Macro
        wrote on last edited by
        #3

        Thanks for your suggestion. I know that i have to use this in *keyPressEvent(QKeyEvent e) slot. Inside that slot only i tried using this Qt::key_Period. But i couldn't get the solution.

        Thanks & Regards

        1 Reply Last reply
        0
        • H Offline
          H Offline
          hpollak
          wrote on last edited by
          #4

          See the "tetrix-example":http://qt-project.org/doc/qt-5.0/qtwidgets/widgets-tetrix.html

          search for "void TetrixBoard::keyPressEvent(QKeyEvent *event)".

          I fthink your solution should look like this ( QLineEdit allso inherits QWidgets ).

          1 Reply Last reply
          0
          • H Offline
            H Offline
            hpollak
            wrote on last edited by
            #5

            in event-Pointer you can call key() returning the pressed key.

            1 Reply Last reply
            0
            • C Offline
              C Offline
              cincirin
              wrote on last edited by
              #6

              @
              '.' == QKeyEvent::key()
              @

              don't work ?

              1 Reply Last reply
              0
              • M Offline
                M Offline
                Macro
                wrote on last edited by
                #7

                Nope... It doesn't work.. :-(

                Thanks & Regards

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  Sam
                  wrote on last edited by
                  #8

                  One more approach can be to override the eventFilter() function of the lineEdit like :-

                  @bool eventFilter(QObject *target, QEvent *event);@

                  and in the implementation you can try

                  @bool MyLineEdit::eventFilter(QObject *target, QEvent *event)
                  {
                  if (event->type() == QEvent::KeyPress)
                  {
                  QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
                  if (keyEvent->key() == Qt::Key_Period)
                  {
                  //doSomething
                  return QWidget::eventFilter(target, event)
                  }
                  }
                  return QWidget::eventFilter(target, event);
                  }@

                  Note : The above approach can be used if you are creating your own custom lineEdit, the keypressevent() will also work incase of custom lineEdit, If you are not using a custom lineEdit then you need to use installEventFilter() on you widget and use the above approach/function but you need to check if target is equal to the lineEdit instance.

                  Written brain to terminal not tested

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    Macro
                    wrote on last edited by
                    #9

                    Cool.... That Works Fine.... Thanks a lot Sam..... :-)

                    Thanks & Regards

                    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