Results 1 to 18 of 18

Thread: virtual keyboard done with qt4-designer

  1. #1
    Join Date
    Apr 2007
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question virtual keyboard done with qt4-designer

    Hi there all!


    Has anyone out there a "virtual keyboard" done with qt4-designer and can deliver the sources?
    I need this for quick testing purposes.
    The idea is to use this virtual or better software-keyboard to fire letters like A to Z, arrow up, Enter, Escape, plus etc. and do NOT use the hardware keyboard.
    I found out that Designer accepts for push-buttons an icon that can be used (e.g. arrow up).

    I have used the qt- and google-search but found only:
    Qtopia has a so called virtual keyboard in Qtopia Phone and qtmail but no screenshot is available,
    reading the instructions for getting and building the sources (?) you get nearly mad.
    So the next questions come up: Can I use Qtopia on "normal" boxes (not on embedded systems) with Designer-help? Is there an abstraction-layer between the picture of the keyboard-layout and the sources?


    I would be very happy to get in minimum a link for the icons for the layout (maybe a library?).



    Thanks
    Regards

    Klaus

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

    Default Re: virtual keyboard done with qt4-designer

    Can I use Qtopia on "normal" boxes (not on embedded systems) with Designer-help? I
    You don't need that.
    All you need are the classes (code), you can compile it with normal Qt4 then.
    At worst, you will have minor adjustment to make to the code, if any.

    The problem is not the gui - but the receiving end of the virtual keyboard.
    Should the virtual keyboard only work inside its own program, or should it be "global" so that it will type in to other applications text boxes?

    If its the first option, then what is the problem having a bunch of butons on a dialog sending KeyPressed events?
    ==========================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.

  3. #3
    Join Date
    Oct 2010
    Location
    Bangalore
    Posts
    14
    Qt products
    Qt4 Qt/Embedded

    Default Re: virtual keyboard done with qt4-designer

    Hi, I have designed 12 screens for our project. Now our project needs virtual keyboard implementation. I downloaded virtual keyboard from the forum and added to my project.

    I want to show the virtual keyboard whenever clicked on line edit. For this I've written one "eventFilter(QObject* call_object, QEvent* pevent)" function.

    The VKB pop ups if I click on line edit, but the problem is, if I move the mouse pointer on the VKB the keyboard disappears and appears on the other screen.

    and there if I click on any key the application terminates.

    bool TME_COM::eventFilter(QObject* call_object, QEvent* pevent)
    {


    QLineEdit *isQLineEdit = static_cast<QLineEdit*>(call_object);

    if(!isQLineEdit) return false;

    if (pevent->type() == QEvent::MouseButtonPress)
    {
    ;
    virtualKeyBoard->show();
    return true;

    }else

    return false;
    }

    this is the function I used. so, the questions are

    can any body help, to solve these two problems(1.VKB appears on other screen and 2.program terminates if clicked on key on the other screen)

    please reply as soon as possible.
    Thanks in advance

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

    Default Re: virtual keyboard done with qt4-designer

    isQLineEdit will always be true, even if its not a QLineEdit who sent the vent.
    Which can casue all kinds of not wanted behavior.
    Also, when using plymorphisem, you should not use static_cast, but dynamic_cast.
    Actually static_cast is evil, and should not be used except for very few cases.

    you should test it like this:
    Qt Code:
    1. if( call_object != pLineEdit) return; //where pLineEdit is the pointer to the clicked line edit.
    To copy to clipboard, switch view to plain text mode 
    ==========================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.

  5. #5
    Join Date
    Oct 2010
    Location
    Bangalore
    Posts
    14
    Qt products
    Qt4 Qt/Embedded

    Default Re: virtual keyboard done with qt4-designer

    thanks for the reply, I tried with the above statement but it didn't work. I tried with using signals and slots as follows

    connect(qApp, SIGNAL(focusChanged(QWidget*, QWidget*)), this, SLOT(setWidgets(QWidget*, QWidget*)));

    void TME_COM::setWidgets(QWidget * old, QWidget *newwid)
    {
    const char* ab;
    if(newwid != 0)
    {
    ab = newwid->metaObject()->className();
    qDebug(ab);
    if(strcmp(ab,"QLineEdit")==0)
    {
    qDebug("focus on line edit\n");
    virtualkeyboard->show();
    }
    else
    {
    virtualkeyboard->hide();
    }
    }
    }

    it worked, but I stuck with another problem.
    Virtual keyboard is appearing with out title bar.

    In virtual keyboard constructor, there is a statement like this
    this->setWindowFlags(Qt::Tool);

    If I remove this statement, the program is entering infinite loop and if I include the above statement VKB works, but appears without title bar.
    I want to display VKB with title bar and it should work fine.

    please help me.

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

    Default Re: virtual keyboard done with qt4-designer

    thanks for the reply, I tried with the above statement but it didn't work.
    Then you are doing something else wrong.
    Testing for the object address MUST work.
    Can you show the code you tried which didn't work?
    The code you posted here is totally diferent than the one you posted with your question (different function input parameters)

    your code works only because you have one QLineEdit.
    But if you'll have more than one, your code wont work anymore, since all QLineEdits will have the same class name.

    Its hard to say why your code gets int to an endless loop, from the code you posted.
    It seems that you have a design problem.

    P.S
    Please post code in code tags, its hard to read it they way you posted it.

    In addition, why do you use such an ansafe and complicated code?
    Use QString instead of char*.
    Then you can use opertator '==' insteader of memcmp().
    ==========================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.

  7. #7
    Join Date
    Oct 2010
    Location
    Bangalore
    Posts
    14
    Qt products
    Qt4 Qt/Embedded

    Default Re: virtual keyboard done with qt4-designer

    sorry for the late reply.

    Here is the code which didn't work.

    Qt Code:
    1. bool TME_COM::eventFilter(QObject* call_object, QEvent* pevent)
    2. {
    3. QLineEdit *isQLineEdit = static_cast<QLineEdit*>(call_object);
    4. if(call_object != isQLineEdit)
    5. return false;
    6. if(pevent->type() == QEvent::FocusIn)
    7. {
    8. virtualkeyboard->show();
    9. }
    10. return true;
    11. }
    12. else
    13. {
    14. virtualkeyboard->hide();
    15. return false;
    16. }
    To copy to clipboard, switch view to plain text mode 

    you are right, our design is having more QLineEdits. Out of 12 screens in our project 3 screens are having line edits. I want to show the VKB for these 3 screens.
    I'm totally confused that how to show the virtual keyboard when clicked on line edit. Please give me a function, which I can use to show virtual keyboard for the line edits.

    Additional Info about the project:
    1. We have navigator menu, which has the push buttons linked to all other screens. i.e., when clicked on push button on the screen respective screen opens.
    2. The navigator menu inherits QWidget class, the 3 screens where I want to show the VKB are non modal dialogs,which inherits QDialog class.

    As I told earlier if I include the slot setWidgets program is entering infinite loop. Is there any alternate function or slot for setWidgets slot so that I can try.
    Last edited by madhukiranmp; 8th November 2010 at 05:44.

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

    Default Re: virtual keyboard done with qt4-designer

    This part of the code:
    Qt Code:
    1. QLineEdit *isQLineEdit = static_cast<QLineEdit*>(call_object);
    2. if(call_object != isQLineEdit)
    3. return false;
    To copy to clipboard, switch view to plain text mode 

    makes no sense.
    You are getting an address and then ask if the address you got is the address you got,and of course they are the same!
    You have to check not the address against it self, but against the address of the QLineEdit you want to check!
    That line edit is defined somewhere in your application probably in a ui file (if you use them).
    Have a look at the post I posted where I suggested to you to do that and you will see my remark:
    "where pLineEdit is the pointer to the clicked line edit."
    ==========================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.

  9. #9
    Join Date
    Oct 2010
    Location
    Bangalore
    Posts
    14
    Qt products
    Qt4 Qt/Embedded

    Default Re: virtual keyboard done with qt4-designer

    Qt Code:
    1. bool TME_COM::eventFilter(QObject* call_object, QEvent* pevent)
    2. {
    3. QLineEdit *isQLineEdit = dynamic_cast<QLineEdit*>(call_object);
    4.  
    5. if(call_object != ui->TME_COM_ETHER1_IP1_TXTED) return false;
    6. if(isQLineEdit)
    7. {
    8. if (pevent->type() == QEvent::FocusIn)
    9. {
    10. virtualkeyboard->show();
    11. }
    12. return true;
    13. }
    14. else
    15. {
    16. virtualkeyboard->hide();
    17. return false;
    18. }
    19. }
    To copy to clipboard, switch view to plain text mode 

    This is the code part that I tried with your suggestion, TME_COM_ETHER1_IP1_TXTED is the pointer to the line edit for which I want to show the VKB. But It dint work
    One more thing there are more than one line edits in this screen, I want to display the VKB for each line edit.

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

    Default Re: virtual keyboard done with qt4-designer

    You don't need the check "if(isQLineEdit) since 'isQLineEdit' gets the address from 'call_object', and from the top of my head I think 'call_object' will never be NULL, since if no object sent and event no event is sent - which mean 'call_object' should never be NULL.
    If at all you should check 'call_object != NULL', since you use it before you use 'isQLineEdit'.
    That was a side note.

    Now your code looks better, and it looks it should do what you want.
    You didn't explain what you mean by "not working".
    That can mean all kinds of things.
    Put a break point , step through, and have a look which part of the code is not doing what you expect - you might see then also why.
    Did you call installEventFilter() for the QLineEdits for which you want to catch the focus in event?

    One more thing there are more than one line edits in this screen, I want to display the VKB for each line edit.
    Just repeat the code for the line edit you have now for each of the line edits you want to have the VKB.
    ==========================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.

  11. #11
    Join Date
    Oct 2010
    Location
    Bangalore
    Posts
    14
    Qt products
    Qt4 Qt/Embedded

    Default Re: virtual keyboard done with qt4-designer

    Qt Code:
    1. bool TME_COM::eventFilter(QObject* call_object, QEvent* pevent)
    2. {
    3. QLineEdit *isQLineEdit = static_cast<QLineEdit*>(call_object);
    4.  
    5. if(call_object != ui->TME_COM_ETHER1_IP1_TXTED) return false;
    6. qDebug("Entering if\n");
    7. if (pevent->type() == QEvent::FocusIn)
    8. {
    9. qDebug("entering show\n");
    10. virtualkeyboard->show();
    11. return true;
    12. }
    13. else
    14. {
    15. qDebug("entering hide\n");
    16. virtualkeyboard->hide();
    17. return false;
    18. }
    19. }
    To copy to clipboard, switch view to plain text mode 

    Yes, Of-course I've called installEventFilter() for the line edits.
    "Not working" I mean if I click on line edit VKB is not displaying.
    So as you told I put some Debug statements and tried, actually when I open the screen itself it's entering this event filter function. The program is not waiting till I click on lline edit. As soon as I open the TME_COM screen it's entering the event filter function. But I don't want that, whenever I click on line edit it should enter the event filter function.

    In the output It's printing following Debug statements

    Entering if
    Entering hide
    Entering if
    Entering hide

    and I'm getting one warning," unused variable isQlineEdit". What should I do to display the VKB for click on line edit?

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

    Default Re: virtual keyboard done with qt4-designer

    The program is not waiting till I click on lline edit. As soon as I open the TME_COM screen it's entering the event filter function. But I don't want that, whenever I click on line edit it should enter the event filter function.
    That is a correct behaviour.
    An event filter gets all the events for the filtered widget.
    In the function it self, as you are doing, you should filter out the event you want to handle.
    So that is ok.

    The warning you get tells you what the problem is - you have defined 'isQlineEdit' but you don't use it.
    Just delete that line and the warning will go away.

    Try 'QEvent::EnterEditFocus' instead of 'QEvent::FocusIn'

    Yes, Of-course I've called installEventFilter() for the line edits.
    Well, nothing is 'of course' when you try to debug code you can't see
    ==========================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.

  13. #13
    Join Date
    Oct 2010
    Location
    Bangalore
    Posts
    14
    Qt products
    Qt4 Qt/Embedded

    Default Re: virtual keyboard done with qt4-designer

    I tried with 'QEvent::EnterEditFocus', with this also VKB is not displaying, actually it's saying "EnterEditfocus is not a member of QEvent ".
    Is there any function other than eventFilter(), so that I can use here. Because, I don't want to show the keyboard as soon as the screen opens. Instead, I want to display the VKB only when clicked on line edit.


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

    Default Re: virtual keyboard done with qt4-designer

    "EnterEditfocus is not a member of QEvent ".
    It should be EnterEditFocus, with a 'F'.

    In such cases check the QEvent documentation.

    s there any function other than eventFilter(), so that I can use here.
    You can subclass QLineEdit and overload focusInEvent().
    But then your QLineEdit will have to get a pointer to the VKB, or otherwise have access to it.

    Don't expect to be fed everything with a spoon - read the docs!
    Look for answers in the docs!
    ==========================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.

  15. #15
    Join Date
    Oct 2010
    Location
    Bangalore
    Posts
    14
    Qt products
    Qt4 Qt/Embedded

    Default Re: virtual keyboard done with qt4-designer

    Okay, I'll try with that. Thank you.

  16. #16
    Join Date
    Oct 2010
    Location
    Bangalore
    Posts
    14
    Qt products
    Qt4 Qt/Embedded

    Default Re: virtual keyboard done with qt4-designer

    Hi. I got it worked with following, using signals and slots

    Qt Code:
    1. connect(qApp, SIGNAL(focusChanged(QWidget*, QWidget*)), this, SLOT(setWidgets(QWidget*, QWidget*)));
    2.  
    3. void TME_COM::setWidgets(QWidget *old, QWidget *newwid)
    4. {
    5. const char* ab;
    6. if(newwid != 0)
    7. {
    8. ab = newwid->metaObject()->className();
    9. if(strcmp(ab,"QLineEdit")==0)
    10. {
    11. virtualKeyBoard->show();
    12. }
    13. }
    14.  
    15. else
    16. {
    17. virtualKeyBoard->hide();
    18. }
    19. }
    To copy to clipboard, switch view to plain text mode 

    Thanks for your replies.
    I've got one more issue.
    The screens in our project resizes when double clicked on title bar. I want to disable this resize option.
    so the questions are,
    1. How to disable the resize of the screens or widget on double click of the title bar?
    2. How to disable the context menu display, when right clciked on title bar?

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

    Default Re: virtual keyboard done with qt4-designer

    Hi. I got it worked with following, using signals and slots
    I was not aware the trolls added a signal for that, its hard to keep up with all the new features! (All though I see its a 4.1 feature (but I didn't need it))
    Well, I learned something new too!
    1. How to disable the resize of the screens or widget on double click of the title bar?
    I don't know if Qt has something "ready" to be used for that.
    You might need to catch the resize event for the window and re implement it.
    2. How to disable the context menu display, when right clciked on title bar?
    See WindowFlags.
    ==========================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.

  18. #18
    Join Date
    Oct 2010
    Location
    Bangalore
    Posts
    14
    Qt products
    Qt4 Qt/Embedded

    Default Re: virtual keyboard done with qt4-designer

    Hi all,
    I have created a simple application with a single combo box and some push buttons. This is to implement multilingual feature of Qt. I want to dynamically update the combo box if any new .qm file is added to the project folder. I'm getting the file name added to the combo box. But once I select the dynamically added item in the combo box the language changes and the corresponding new item disappears. I want it to be added permanently. please help how to do this.
    Thanks in advance.

    here is the code I've used
    Qt Code:
    1. #include "detect.h"
    2. #include "ui_detect.h"
    3. #include "QFileSystemWatcher"
    4. #include "QFileInfo"
    5. #include "QTranslator"
    6. #include "QTextStream"
    7. #include "QString"
    8. #include "QComboBox"
    9.  
    10. QTranslator langTranslator;
    11. QString line1;
    12. detect::detect(QWidget *parent) :
    13. QDialog(parent),
    14. ui(new Ui::detect)
    15. {
    16. ui->setupUi(this);
    17. qApp->installTranslator(&langTranslator);
    18. system("ls ..\ >new.txt");
    19. system("comm -13 old.txt new.txt >difference.txt");
    20. readdifference();
    21.  
    22. }
    23.  
    24. detect::~detect()
    25. {
    26. delete ui;
    27. }
    28.  
    29. void detect::changeEvent(QEvent *e)
    30. {
    31. QDialog::changeEvent(e);
    32. switch (e->type()) {
    33. case QEvent::LanguageChange:
    34. ui->retranslateUi(this);
    35. break;
    36. default:
    37. break;
    38. }
    39. }
    40.  
    41. void detect::on_comboBox_activated(const QString & text)
    42. {
    43. if(text == tr("French"))
    44. {
    45. langTranslator.load("arrowpad_fr","C:/Documents and Settings/20010833/Desktop/testdet" );
    46. }
    47. else if(text == line1)
    48. {
    49. langTranslator.load(line1,"C:/Documents and Settings/20010833/Desktop/testdet" );
    50. }
    51.  
    52. }
    53. void detect::readdifference()
    54. {
    55. QString path="C:/Documents and Settings/20010833/Desktop/testdet";
    56. QFile nfile("difference.txt");
    57.  
    58. if(!nfile.open(QIODevice::ReadOnly ))
    59. return;
    60. QTextStream in(& nfile);
    61. while(!in.atEnd())
    62. {
    63. line1=in.readLine();
    64. if(line1.endsWith("qm"))
    65. {
    66.  
    67. ui->comboBox->addItem(line1,QVariant::Char);
    68. // break;
    69. }
    70. }
    71. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by madhukiranmp; 30th December 2010 at 09:53.

Similar Threads

  1. Virtual Keyboard on Qtopia 4.2.1
    By shapirlex in forum Qt for Embedded and Mobile
    Replies: 2
    Last Post: 11th April 2007, 16:51
  2. Compiling error
    By vfernandez in forum Newbie
    Replies: 2
    Last Post: 9th March 2007, 22:02
  3. virtual keyboard
    By sar_van81 in forum Qt Programming
    Replies: 5
    Last Post: 22nd December 2006, 14:40
  4. Replies: 13
    Last Post: 15th December 2006, 12:52
  5. Adding slots in Designer
    By jamos in forum Qt Tools
    Replies: 5
    Last Post: 19th May 2006, 00:28

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.