How to identify the button text to be changed when click on Caps lock for developing keyboard



  • Hi,

    developing the keyboard.

    0_1502451540595_Screenshot (44).png

    I have used customized button , inherited from QPushbutton,
    on click of Caps , how do i know the respective buttons and change the text.

    code below of how i implemented.

    MyPushButton .h

    class MyPushButton : public QPushButton
    {
        Q_OBJECT
    public:
        MyPushButton(QString value, int checkvalue, QWidget *parent = 0);
        ~MyPushButton();
    
    protected:
        void mousePressEvent(QMouseEvent *event);
    
    signals:
        void emitString_SIGNAL(QString);
    };
    

    MyPushButton .cpp

    MyPushButton::MyPushButton(QString value, int checkvalue, QWidget *parent)
        :QPushButton(parent)
    {
        qDebug () << "keyboard value :" << value;
        this->setObjectName(value);
        qDebug () << "objectname :" << this->objectName() << endl;
    
        if(checkvalue == 0 || checkvalue == 4)
        {
            this->setText(value);
        }
        else if(checkvalue == 1)
        {
            QPixmap pixmap(":/OthersFiles/Images/backspace.png");
            QIcon ButtonIcon(pixmap);
            this->setIcon(ButtonIcon);
        }
        else if(checkvalue == 2)
        {
            QPixmap pixmap(":/OthersFiles/Images/enter.png");
            QIcon ButtonIcon(pixmap);
            this->setIcon(ButtonIcon);
        }
        else if(checkvalue == 3)
        {
            QPixmap pixmap(":/OthersFiles/Images/arrowUp.png");
            QIcon ButtonIcon(pixmap);
            this->setIcon(ButtonIcon);
        }
        else if(checkvalue == 5)
        {
            QPixmap pixmap(":/OthersFiles/Images/multilingualicon.png");
            QIcon ButtonIcon(pixmap);
            this->setIcon(ButtonIcon);
        }
        else if(checkvalue == 7)
        {
            QPixmap pixmap(":/OthersFiles/Images/close1.jpg");
            QIcon ButtonIcon(pixmap);
            this->setIcon(ButtonIcon);
        }
    }
    
    
    
    void MyPushButton::mousePressEvent(QMouseEvent *event)
    {
        Q_UNUSED(event)
    
        qDebug () << "key pressed :" << this->text() << this->objectName() << endl;
    
        QString text = this->text();
        QString strobjectName = this->objectName();
        qDebug () << "key pressed :" << this->text() << strobjectName << endl;
    
        emit emitString_SIGNAL(text);
    
    
    }
    

    Keyboard.cpp

    void KeyboardLayout::createKeyboardLayout()
    {
        m_hbox->addWidget(addKeys(tr("Q"),characters));
        m_hbox->addWidget(addKeys(tr("W"),characters));
        m_hbox->addWidget(addKeys(tr("E"),characters));
        m_hbox->addWidget(addKeys(tr("R"),characters));
        m_hbox->addWidget(addKeys(tr("T"),characters));
        m_hbox->addWidget(addKeys(tr("Y"),characters));
        m_hbox->addWidget(addKeys(tr("U"),characters));
        m_hbox->addWidget(addKeys(tr("I"),characters));
        m_hbox->addWidget(addKeys(tr("O"),characters));
        m_hbox->addWidget(addKeys(tr("P"),characters));
        m_hbox->addWidget(addKeys("backspaceicon",backspace_icon));
    
        m_vbox->insertLayout(0,m_hbox);
    
    
        m_hbox1->addWidget(addKeys(tr("A"),characters));
        m_hbox1->addWidget(addKeys(tr("S"),characters));
        m_hbox1->addWidget(addKeys(tr("D"),characters));
        m_hbox1->addWidget(addKeys(tr("F"),characters));
        m_hbox1->addWidget(addKeys(tr("G"),characters));
        m_hbox1->addWidget(addKeys(tr("H"),characters));
        m_hbox1->addWidget(addKeys(tr("J"),characters));
        m_hbox1->addWidget(addKeys(tr("K"),characters));
        m_hbox1->addWidget(addKeys(tr("L"),characters));
        m_hbox1->addWidget(addKeys("entericon",enter_icon));
    
        m_vbox->insertLayout(1,m_hbox1);
    
    
        m_hbox2->addWidget(addKeys("capsicon",caps_icon));
        m_hbox2->addWidget(addKeys(tr("Z"),characters));
        m_hbox2->addWidget(addKeys(tr("X"),characters));
        m_hbox2->addWidget(addKeys(tr("C"),characters));
        m_hbox2->addWidget(addKeys(tr("V"),characters));
        m_hbox2->addWidget(addKeys(tr("B"),characters));
        m_hbox2->addWidget(addKeys(tr("N"),characters));
        m_hbox2->addWidget(addKeys(tr("M"),characters));
        m_hbox2->addWidget(addKeys(tr(","),characters));
        m_hbox2->addWidget(addKeys(tr("."),characters));
        m_hbox2->addWidget(addKeys("capsicon",caps_icon));
    
    
        m_vbox->insertLayout(2,m_hbox2);
    
    
        m_hbox3->addWidget(addKeys("&123",numbers));
        m_hbox3->addWidget(addKeys("multilingual",multilingual_icon));
        m_hbox3->addWidget(addKeys("spacebar",spacebar));
        m_hbox3->addWidget(addKeys(",",characters));
        m_hbox3->addWidget(addKeys(":-)",characters));
        m_hbox3->addWidget(addKeys("close",close_icon));
    
        m_vbox->insertLayout(3,m_hbox3);
    
    
        this->setLayout(m_vbox);
    }
    
    QPushButton *KeyboardLayout::addKeys(QString strValue, int icheckValue)
    {
        button = new MyPushButton(strValue,icheckValue,this);
        connect(button,SIGNAL(emitString_SIGNAL(QString)),this,SLOT(getPushButton_TextSLOT(QString)));
       
        return button;
    }
    

    How do i change the text of buttons to lower case?. on click of up arrow..

    Thanks,


  • Moderators

    @Pradeep-Kumar Iterate over all the buttons and for each do

    button->setText(button->text().toLower());
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.