Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

[Solved] Software Keyboard in QT



  • Dear All,

    I am developing an onscreen keyboard using QT. It looks similar to the hardware QWERTY keyboard.
    I want to do following:

    On press of CAPS button, all the buttons should display capital letters. and vice versa.

    What is the best suitable approach to achieve this functionality.

    Kindly give your suggestions.

    Thanks
    Sid



  • Create a different widgets with Capital letters & Small letters. Switch between these visual elements or get the existing text and convert it to Upper or *Lower *based on the condition.
    In summery there is no direct easy way of doing it, its all a manual process.


  • Moderators

    Hi,

    If you're going QML way then binding would be enough :)



  • In Qt or QML you can create flag isShift. Then in your button control you can change caption or image in depending on isShift flag.

    For example:
    QML
    @
    DigitalButton {
    caption: isShift ? upperChar : lowerChar
    ...
    }@

    Qt:
    @
    slots:
    void onShiftChanged() {
    setCaption(isShift ? upperChar : lowerChar )
    }
    @



  • Thanks a lot for the suggestions.

    I finally achieved this using the below code:

    @
    for (int i = 0; i < m_contentsLayout->count();i++) {
    if (QWidgetItem myItem = dynamic_cast <QWidgetItem>(m_contentsLayout->itemAt(i))) {

    QPushButton *w = dynamic_cast <QPushButton*>(myItem->widget());
    if(w != NULL)
    {
            //qDebug()<<"Button Text:"<<w->text();
     QString str = w->text();
     if(m_bPressedCapsLock)
      w->setText(str.toUpper());
     else
      w->setText(str.toLower());
    }
                        }}
    

    @



  • Thanks for the suggestions. I am making this completed.



  • Nevertheless, I suggest you create custom widget KeyboardButton and use signals/slots instead your loop. This approach is more flexible and extendable.


Log in to reply