Important: Please read the Qt Code of Conduct -

How to set focus on QLineEdit while QTextEdit still active?

  • I want QLineEdit to be focus for editing while emit textChanged signal
    to QTextEdit for text selection.

    It's work fine after emit signal but I have to setFocus on QTextEdit
    to get active selected text and now QLineEdit has lost focus
    to editing cause the focus is on QTextEdit.

    How to set QTextEdit just for active selected text without lost focus from QLineEdit?

  • Moderators

    You don't need to mess with focus of QTextEdit. It's just that by default color of highlight of inactive control is the same as unselected. Change it to be the same color as the active highlight and you're good to go:

    auto p = textEdit->palette();
    p.setColor(QPalette::Inactive, QPalette::Highlight, p.color(QPalette::Active, QPalette::Highlight));
    p.setColor(QPalette::Inactive, QPalette::HighlightedText, p.color(QPalette::Active, QPalette::HighlightedText));

  • Oh. I never think in this way. lol

Log in to reply