Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to identify the button text to be changed when click on Caps lock for developing keyboard
Qt 6.11 is out! See what's new in the release blog

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

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 1.1k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Pradeep KumarP Offline
    Pradeep KumarP Offline
    Pradeep Kumar
    wrote on last edited by Pradeep Kumar
    #1

    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,

    Pradeep Kumar
    Qt,QML Developer

    jsulmJ 1 Reply Last reply
    0
    • Pradeep KumarP Pradeep Kumar

      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,

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

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

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

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved