[SOLVED] QPlainTextEdit how to make findAll looks native



  • Hi,

    I've implemented a finAll(const QString& expression) method in a class sublassed from QPlainTextEdit. This method is intented to higlight every occurence of "expression". In the implementation, I make use of QExtraSelection like this :

    @
    QTextEdit::ExtraSelection extra;
    extra.format.setBackground(Theme color here ?);
    @

    But I dont know what to give to setBackground method. I would like to get the color used in QPlainTextEdit::find method and to use it. Therefore the highlight all behavior will look "native". For the moment I use Qt::blue color but it looks ugly.

    Hope you guys understood me and have a clue ;)

    Thanx in advance ;)



  • The "QPalette":https://qt-project.org/doc/qt-4.7/qpalette.html class is used to describe the colour scheme for your application. It defines 'roles' for all the common colour requirements including highlighting therefore, to get the native highlight colour, try something like:

    @
    QApplication::palette()->highlight()
    @

    Hope this helps ;o)



  • This does work : QApplication::palette().highlight()

    Thx a lot ;)

    But i still have a problem.

    When i do a QPlainTextEdit::find, the matched text is white with a blue background. But when I use the QExtraSelection, the background is blue but the text is still black. How can I make the text color change to white ?



  • Set the formats foreground colour to:

    @
    extra.format.setForeground(QApplication::palette.highlightedText());
    @



  • Thanx so much. I'll mark it as solved


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.