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

QTextEdit text color.

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 15.8k 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.
  • S Offline
    S Offline
    Sam
    wrote on last edited by
    #1

    I have a logger that writes to the QTextEdit. I want to add a functionality that whenever the logger starts , it should check the textEdit has some text, if yes then the previous text color should change to grey , similar to QTextEdit functionality used in Qt Creator.

    I am able to achieve this using

    @if (!m_output->toPlainText().isEmpty())
    {
    QString textEditString = m_output->toHtml();

     m_output->clear();
     m_output->setHtml(QString("<font color=grey> %1 </font>").arg(textEditString));
    

    }@

    just want to know if there is any alternative way to achieve the same effect.

    1 Reply Last reply
    0
    • napajejenunedk0N Offline
      napajejenunedk0N Offline
      napajejenunedk0
      wrote on last edited by
      #2

      http://qt-project.org/doc/qt-4.8/QTextEdit.html

      Have you tried setTextColor?

      You could also use setPalette:
      http://qt-project.org/doc/qt-4.8/qwidget.html

      ... but I think it is recommended to use the html syntax instead.

      1 Reply Last reply
      0
      • V Offline
        V Offline
        vezprog
        wrote on last edited by
        #3

        Style sheets is another way...

        @
        QString styleSheet = "#m_output { color: rgb(0, 20, 50); }";
        m_output->setStyleSheet(styleSheet);
        @

        where your rgb color can be what ever you would like. Make sure you set your accessible name and your object name to the name described after your # sign in the style sheet string.

        so, where ever your constructor is that creates the button, immediately after creation, do:
        @
        m_output->setObjectName("m_output");
        m_output->setAccessibleName("m_output");
        @

        Then set the style sheet dynamically through code. You can customize the whole object with style sheets, color, shape, background color, ect.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          Sam
          wrote on last edited by
          #4

          [quote author="dvez43" date="1358191619"]Style sheets is another way...

          @
          QString styleSheet = "#m_output { color: rgb(0, 20, 50); }";
          m_output->setStyleSheet(styleSheet);
          @

          where your rgb color can be what ever you would like. Make sure you set your accessible name and your object name to the name described after your # sign in the style sheet string.

          so, where ever your constructor is that creates the button, immediately after creation, do:
          @
          m_output->setObjectName("m_output");
          m_output->setAccessibleName("m_output");
          @

          Then set the style sheet dynamically through code. You can customize the whole object with style sheets, color, shape, background color, ect.[/quote]

          Thanks dvez43,

          The problem with stylesheet is that once we set the stylesheet it reflects foreach text in textEdit, but my requirement is to change the previous text entry to grey and the currrent text added should have color which is specified/hardcoded.

          I am able to achieve the same behaviour, the issue is that i am first storing it to a string then clearing the textEdit and then adding the previous text again with grey color, which i think is not suitable.

          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