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?
Forum Updated to NodeBB v4.3 + New Features

How to set QPlainTextEdit text background color?

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 8.7k 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 8 Jul 2016, 05:30 last edited by Violet Giraffe 7 Aug 2016, 05:33
    #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 8 Jul 2016, 05:48
    0
    • V Violet Giraffe
      8 Jul 2016, 05:30

      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 8 Jul 2016, 05:48 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
        8 Jul 2016, 05:30

        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 8 Jul 2016, 08:20 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 8 Jul 2016, 16:08
        1
        • D Devopia53
          8 Jul 2016, 08:20

          @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 8 Jul 2016, 16:08 last edited by
          #4

          @Devopia53 said:

          must specify a selector.

          That's it, thanks!

          1 Reply Last reply
          0

          1/4

          8 Jul 2016, 05:30

          • Login

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