Search code examples
c++qtuser-interfaceqlineeditqpushbutton

How to make linedit ready to be typed into when pushbutton is clicked


In my program, the user has to regularly push a button and then type a number into linedit. Every time the user clicks the button they have to click on the linedit again so they can type into it. Is there a way to automate this process so when the user clicks the button, linedit is ready to be typed into.


Solution

  • What you need to do is to invoke the setFocus() method of QLineEdit. See the example below,

    void MyWidget::on_pushButton_clicked()
    {
       ui->lineEdit->setFocus();
    
    }