Results 1 to 18 of 18

Thread: virtual keyboard done with qt4-designer

Hybrid View

Previous Post Previous Post   Next Post Next Post
  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,714
    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,714
    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,714
    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 04:44.

  8. #8
    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: 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,714
    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?

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, 15:51
  2. Compiling error
    By vfernandez in forum Newbie
    Replies: 2
    Last Post: 9th March 2007, 21:02
  3. virtual keyboard
    By sar_van81 in forum Qt Programming
    Replies: 5
    Last Post: 22nd December 2006, 13:40
  4. Replies: 13
    Last Post: 15th December 2006, 11:52
  5. Adding slots in Designer
    By jamos in forum Qt Tools
    Replies: 5
    Last Post: 18th May 2006, 23: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
  •  
Qt is a trademark of The Qt Company.