Results 1 to 5 of 5

Thread: How to disable CTRL+V on a QLineWidget

  1. #1
    Join Date
    Aug 2010
    Posts
    18
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default How to disable CTRL+V on a QLineWidget

    Hi,

    I have one QLineWidget with echo mode as password.
    Now I want to disable CTRL+V on that QlineWidget as I do not want that anybody can paste on that widget using CTRL+V shortcut.

    I have set context menu::No Context Menu which will disable the right click options but I do not know how to disable CTRL+V only on this QLineWidget.

    Can anybody can help me?

    Thanks in advance.
    Sanket

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to disable CTRL+V on a QLineWidget

    There are a couple of ways to do it. One is to subclass QLineEdit and redeclare (that's important!) and reimplement the paste() slot from it to do nothing.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to disable CTRL+V on a QLineWidget

    In addition to what wysota suggested:
    Override the general event handler, or install and eventFileter on the widget, and you can do the following:
    a. I don't know if QLineEdit is using QShortcutEvent events - you can tests that, in your event handler or look at QLineEdit code.
    If it does use the QShortcutEvent - then you just intercept the one you are interested in.
    b. Provided a. is not the case, you can just intercept the normal keypress events an evaluate the current pressed keys.

    But wysota's way is cleaner I think.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to disable CTRL+V on a QLineWidget

    I think that going through key events will not be sufficient, at least on some platforms. While on Windows this might be sufficient, on Unix you can usually paste something from clipboard using the middle mouse button which does not send any key events. That's my guess at least.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: How to disable CTRL+V on a QLineWidget

    Something else to keep in mind: a lot of people, like myself, hate it when others decide what's best for them when it comes to using their own computer. Consider carefully whether the benfits of disabling Ctrl-V outweight the costs in incovnenience.

Similar Threads

  1. filterout the Alt+Ctrl+Del
    By sudhansu in forum Qt Programming
    Replies: 6
    Last Post: 25th March 2010, 07:55
  2. Keypressevent - CTRL Key_Enter
    By qtuser20 in forum Qt Programming
    Replies: 2
    Last Post: 3rd March 2010, 20:47
  3. Why Ctrl+A not working in QListWidget?
    By rajesh in forum Qt Programming
    Replies: 6
    Last Post: 10th December 2009, 14:40
  4. disable ALT+CTRL+DEL!!!!
    By phillip_Qt in forum Qt Programming
    Replies: 10
    Last Post: 3rd November 2009, 09:23
  5. CTrl + A
    By navi1084 in forum Qt Programming
    Replies: 1
    Last Post: 23rd October 2008, 09:19

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.