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. How to set QPlainTextEdit text background color?
Qt 6.11 is out! See what's new in the release blog

How to set QPlainTextEdit text background color?

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 9.9k Views 2 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.
  • V Offline
    V Offline
    Violet Giraffe
    wrote on last edited by Violet Giraffe
    #1

    I've tried setStyleSheet with "background-color: #rrggbb", it does the trick, but it also affects scrollbars. How to set just the text bg color?

    ? D 2 Replies Last reply
    0
    • V Violet Giraffe

      I've tried setStyleSheet with "background-color: #rrggbb", it does the trick, but it also affects scrollbars. How to set just the text bg color?

      ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      Hi!

      QPalette p = ui->plainTextEdit->palette();
      p.setColor(QPalette::Active, QPalette::Base, Qt::black);
      ui->plainTextEdit->setPalette(p);
      ui->plainTextEdit->setBackgroundVisible(false);
      
      1 Reply Last reply
      2
      • V Violet Giraffe

        I've tried setStyleSheet with "background-color: #rrggbb", it does the trick, but it also affects scrollbars. How to set just the text bg color?

        D Offline
        D Offline
        Devopia53
        wrote on last edited by
        #3

        @Violet-Giraffe

        If you want to change only the color of the entire viewport background (except scrollbar), must specify a selector.

        like this:

        ui->plainTextEdit->setStyleSheet("QPlainTextEdit {background-color: #rrggbb;}")
        

        And if you want to set only the text background color,

        like this:

        QTextCharFormat fmt;
        fmt.setBackground(QBrush(Qt::yellow));
        ui->plainTextEdit->mergeCurrentCharFormat(fmt);
        
        V 1 Reply Last reply
        1
        • D Devopia53

          @Violet-Giraffe

          If you want to change only the color of the entire viewport background (except scrollbar), must specify a selector.

          like this:

          ui->plainTextEdit->setStyleSheet("QPlainTextEdit {background-color: #rrggbb;}")
          

          And if you want to set only the text background color,

          like this:

          QTextCharFormat fmt;
          fmt.setBackground(QBrush(Qt::yellow));
          ui->plainTextEdit->mergeCurrentCharFormat(fmt);
          
          V Offline
          V Offline
          Violet Giraffe
          wrote on last edited by
          #4

          @Devopia53 said:

          must specify a selector.

          That's it, thanks!

          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