Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] QPlainTextEdit how to make findAll looks native
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] QPlainTextEdit how to make findAll looks native

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 1.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kevina67
    wrote on last edited by
    #1

    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 ;)

    1 Reply Last reply
    0
    • jazzycamelJ Offline
      jazzycamelJ Offline
      jazzycamel
      wrote on last edited by
      #2

      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)

      For the avoidance of doubt:

      1. All my code samples (C++ or Python) are tested before posting
      2. As of 23/03/20, my Python code is formatted to PEP-8 standards using black from the PSF (https://github.com/psf/black)
      1 Reply Last reply
      0
      • K Offline
        K Offline
        kevina67
        wrote on last edited by
        #3

        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 ?

        1 Reply Last reply
        0
        • jazzycamelJ Offline
          jazzycamelJ Offline
          jazzycamel
          wrote on last edited by
          #4

          Set the formats foreground colour to:

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

          For the avoidance of doubt:

          1. All my code samples (C++ or Python) are tested before posting
          2. As of 23/03/20, my Python code is formatted to PEP-8 standards using black from the PSF (https://github.com/psf/black)
          1 Reply Last reply
          0
          • K Offline
            K Offline
            kevina67
            wrote on last edited by
            #5

            Thanx so much. I'll mark it as solved

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved