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

Custom Input: QLineEdit



  • Looking inside Qt Creator IDE -> Tools -> Options -> Build & Run -> General Tab:
    There is a "Default build directory" input field.

    When I click inside this field, it shows me a "AB" icon on the right side.
    And if I click in this icon, I got a list window with some options...

    I would like to know how can I implement this QLineEdit component with this "right icon" feature.

    0_1566330109976_input_x.jpg
    Could you help me?


  • Lifetime Qt Champion

    Hi,

    Might be QLineEdit::addAction.

    Otherwise, you can take a look at Qt Creator's sources for that field.



  • @sgaist that's right! Thank you!

    QLineEdit *myLineEdit = new QLineEdit(this);
    QAction *myAction = myLineEdit->addAction(QIcon("test.png"), QLineEdit::TrailingPosition);
    connect(myAction, &QAction::triggered, this, &MyClass::onActionTriggered);
    

Log in to reply