How to insert a button inside a QLineEdit

前端 未结 6 959
悲&欢浪女
悲&欢浪女 2020-12-09 06:45

I need help inserting a button inside in a QLineEdit that can call a function.

For example, like this google image:

6条回答
  •  -上瘾入骨i
    2020-12-09 07:15

    In qt C++, I can drag and drop pushButton in the left of LineEdit. After that, I just need to set styleSheet for LineEdit with this code:

    int FramWidth = lineEdit->style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
    
    lineEdit->setStyleSheet(QString("QLineEdit{padding-right: %1px; }").arg(ui->pushButton->sizeHint().width() + FramWidth +5));
    

    And it works for me. Hope it can help.

提交回复
热议问题