Results 1 to 12 of 12

Thread: Is there a way to force QLineEdit to start accepting input with Hebrew as default

  1. #1
    Join Date
    Jan 2006
    Posts
    52
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Is there a way to force QLineEdit to start accepting input with Hebrew as default

    I have a program which is used on windows systems, running Hebrew & English as the default languages. My users are not tech savvy at all (bunch of old granpas ). Now on each run of the program it first ask the user for a name and password - and the name must be in Hebrew (requirements are not mine). I haven't found a way to make sure the program start accepting input with Hebrew as the default so on each start they have to switch to language to Hebrew (using the OS pre-assigned key combination) and then input their user names. Since they start up the program quite of a few times each day this is bugging them.

    I have tried using setLocale() to force Hebrew as the locale for the program and it works for all program defined strings, but not anywhere outside input is concerned.

    So to my question, is it even possible to force QLineEdit to start accepting input with Hebrew as default?


    Thanks for any answer.
    Dave

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Is there a way to force QLineEdit to start accepting input with Hebrew as default

    If I understand you correctly, you only want to have the Hebrew locale for the line edit?
    If so, you can set a locale per widget:
    http://doc.qt.nokia.com/4.6/qwidget.html#locale-prop

  3. #3
    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: Is there a way to force QLineEdit to start accepting input with Hebrew as default

    I think the input method (keyboard layout) is the problem here, not the locale so the proper way would be to programatically switch the Windows keyboard layout to hebrew. In other words it's not the problem with data display (something locale is related to) but data input.
    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.


  4. The following user says thank you to wysota for this useful post:

    dave (11th July 2010)

  5. #4
    Join Date
    Jan 2006
    Posts
    52
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Is there a way to force QLineEdit to start accepting input with Hebrew as default

    Thanks for answering.

    Quote Originally Posted by tbscope View Post
    If I understand you correctly, you only want to have the Hebrew locale for the line edit?
    If so, you can set a locale per widget:
    http://doc.qt.nokia.com/4.6/qwidget.html#locale-prop
    That's what I did. Unfortunately it doesn't affect the input language.

  6. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Is there a way to force QLineEdit to start accepting input with Hebrew as default

    שלום,

    I am afraid but this is OS specific since you want to change the keyboard layout. But I am sure you can change it via the system API every time the line edit gets the focus. (Or, ask the user for the shortcuts he normal uses to change the kb layout and trigger it programmatic.)

    Or (not the best way) install a event handler and check for keyboard inputs and transform e.g. a "D" to "ד".

    Lykurg

  7. The following user says thank you to Lykurg for this useful post:

    dave (11th July 2010)

  8. #6
    Join Date
    Jan 2006
    Posts
    52
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Is there a way to force QLineEdit to start accepting input with Hebrew as default

    Quote Originally Posted by wysota View Post
    I think the input method (keyboard layout) is the problem here, not the locale so the proper way would be to programatically switch the Windows keyboard layout to hebrew. In other words it's not the problem with data display (something locale is related to) but data input.
    That's also the conclusion Lykurg reached. I didn't think of it this way but you're both right.

    Quote Originally Posted by Lykurg View Post
    שלום,

    I am afraid but this is OS specific since you want to change the keyboard layout. But I am sure you can change it via the system API every time the line edit gets the focus. (Or, ask the user for the shortcuts he normal uses to change the kb layout and trigger it programmatic.)

    Or (not the best way) install a event handler and check for keyboard inputs and transform e.g. a "D" to "ד".

    Lykurg
    שלום וברכה

    I think that to trigger the key combination programmatically is the best choice. But I have no idea how to go about it. How would I trigger, for example, a shift and an alt keypress together as an input to the QLineEdit?

    Thanks again

  9. #7
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Is there a way to force QLineEdit to start accepting input with Hebrew as default

    since I am a fan of subclassing, I made a small example with subclassing QLineEdit, but the same could be achieved with an event filter.
    Qt Code:
    1. class HebrewInput : public QLineEdit
    2. {
    3. public:
    4. HebrewInput(QWidget *parent = 0) : QLineEdit(parent)
    5. {
    6. setLocale(QLocale::Hebrew);
    7. }
    8.  
    9. protected:
    10. void keyPressEvent ( QKeyEvent * event )
    11. {
    12. event->accept();
    13. // determine which key is pressed and what hebrew letter it should be. ("switch" over event->key())
    14. QKeyEvent e(QEvent::KeyPress,
    15. Qt::Key_unknown,
    16. Qt::NoModifier,
    17. QString::fromUtf8("ש"));
    18. QLineEdit::keyPressEvent(&e);
    19. }
    20. };
    To copy to clipboard, switch view to plain text mode 

  10. #8
    Join Date
    Jan 2006
    Posts
    52
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Is there a way to force QLineEdit to start accepting input with Hebrew as default

    @Lykurg

    Thanks again. That'll work perfectly.

  11. #9
    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: Is there a way to force QLineEdit to start accepting input with Hebrew as default

    Isn't it easier to switch the keyboard layout on focusInEvent and switch it back on focusOutEvent?
    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.


  12. #10
    Join Date
    Jan 2006
    Posts
    52
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Is there a way to force QLineEdit to start accepting input with Hebrew as default

    Sorry for being obtuse, but how do I switch the keyboard layout?

    P.S in QApplication I found two function that might help: keyboardInputDirection() and keyboardInputLocale() but unfortunately they have no set equivalent.

  13. #11
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Is there a way to force QLineEdit to start accepting input with Hebrew as default

    I never have done that myself and on linux it might be complicated because it depends on the graphical environment (KDE, Gnome, ...).

    For windows you can have a look at http://msdn.microsoft.com/en-us/libr...=VS.85%29.aspx: ActivateKeyboardLayout, GetKeyboardLayout and GetKeyboardLayoutList.

  14. #12
    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: Is there a way to force QLineEdit to start accepting input with Hebrew as default

    On KDE there is probably some dbus call that will do the trick.
    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.


Similar Threads

  1. QLineEdit and input mask
    By tpf80 in forum Qt Programming
    Replies: 7
    Last Post: 9th May 2014, 20:47
  2. How to use input method with QLineEdit in HP-UX (Qt4.5)
    By justalittle in forum Qt Programming
    Replies: 0
    Last Post: 11th March 2010, 09:22
  3. [SOLVED] QLineEdit Input
    By QbelcorT in forum Qt Programming
    Replies: 0
    Last Post: 24th November 2008, 05:37
  4. how to force QLineEdit not null ?
    By lovelypp in forum Qt Programming
    Replies: 3
    Last Post: 25th July 2008, 10:26
  5. QLineEdit check Input
    By raphaelf in forum Newbie
    Replies: 1
    Last Post: 17th August 2006, 15:32

Tags for this Thread

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.