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's text color automatically changed to "grey" (same as placeholder text color)
Forum Updated to NodeBB v4.3 + New Features

QTextEdit's text color automatically changed to "grey" (same as placeholder text color)

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 6 Posters 3.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
    sylorr
    wrote on last edited by
    #1

    My Qt version is 5.6.2, and OS Ubuntu 16.04

    My QTextEdit's text color is white by default. And during the run time, I could change some text content inside. However, when I completely clear the content (say I delete every character inside the text) and re-type some characters, the text color becomes grey, which is same with placeholder's color.
    Right now, my solution is connect signal(textChanged()) to a slot(resetTextColor()). In resetTextColor(), I called setTextColor(Qt::white) to reset the text color. But I think this is a pretty silly solution.
    Note: I call QTextEdit's slot, setText(QString) to change set my content.

    aha_1980A 1 Reply Last reply
    0
    • S sylorr

      My Qt version is 5.6.2, and OS Ubuntu 16.04

      My QTextEdit's text color is white by default. And during the run time, I could change some text content inside. However, when I completely clear the content (say I delete every character inside the text) and re-type some characters, the text color becomes grey, which is same with placeholder's color.
      Right now, my solution is connect signal(textChanged()) to a slot(resetTextColor()). In resetTextColor(), I called setTextColor(Qt::white) to reset the text color. But I think this is a pretty silly solution.
      Note: I call QTextEdit's slot, setText(QString) to change set my content.

      aha_1980A Offline
      aha_1980A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on last edited by
      #2

      hi @sylorr,

      how do you set the colors of your QTextEdit?

      in principle its always best to have a minimal example for us to reproduce.

      thanks

      Qt has to stay free or it will die.

      1 Reply Last reply
      1
      • S Offline
        S Offline
        sylorr
        wrote on last edited by
        #3

        Hi @aha_1980 ,

        I solved this problem already. I am not sure if this could count as a bug/problem.

        Overall, I use stylesheet to change my widget colors. Originally, I set all of my text color to white by applying "QLabel {color: white;}" to my main widget (the root of all widgets). Honestly I don't expect my QTextEdit's (a child of main widget) text color to be changed since it doesn't derive from QLabel. But it does, my text edit color becomes white (default placeholder and cursor are still grey/black). Then it comes to the problem: If I type in some texts, they are in white, but if then I delete them ALL, and type in some texts again, they become grey (same color with placeholder texts).

        I solved this by set a stylesheet individually, "QTextEdit { background-color: black; color: white;}" , now my cursor and placeholder now are also white now (great!).

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          That does indeed sound fishy. Can you provide a minimal compilable example that shows that behaviour ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1
          • S Offline
            S Offline
            SirNullPointer
            wrote on last edited by
            #5

            Hi,
            i run into the same "error".
            the easiest way to reproduce is to just create a QTextEdit and change it's color.

            QTextEdit *edit = new QTextEdit();
            edit->setTextColor(QColor(0, 200, 100));
            

            After building the app, just type some text in the Field and then delete all characters. Afterwards the color will be reset to it's default value (white in my case).

            Think this is not the desired behaviour.

            JonBJ 1 Reply Last reply
            0
            • S SirNullPointer

              Hi,
              i run into the same "error".
              the easiest way to reproduce is to just create a QTextEdit and change it's color.

              QTextEdit *edit = new QTextEdit();
              edit->setTextColor(QColor(0, 200, 100));
              

              After building the app, just type some text in the Field and then delete all characters. Afterwards the color will be reset to it's default value (white in my case).

              Think this is not the desired behaviour.

              JonBJ Online
              JonBJ Online
              JonB
              wrote on last edited by
              #6

              @SirNullPointer
              Since this seems like unexpected behaviour (I have never had a problem), have you set up this up in a standalone, minimal program, with whatever minimal stylesheet required to show problem? Because otherwise we might wonder about whatever else is going on in your application....

              1 Reply Last reply
              0
              • Christian EhrlicherC Online
                Christian EhrlicherC Online
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #7

                I think this is described here: https://bugreports.qt.io/browse/QTBUG-19994

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                1 Reply Last reply
                2
                • S Offline
                  S Offline
                  SirNullPointer
                  wrote on last edited by
                  #8

                  yes, it's the problem described in the bugreport.
                  however, in my case the text color is white afterwards.
                  On the white background of the textEdit, it is unreadable from that moment on.

                  1 Reply Last reply
                  0
                  • Christian EhrlicherC Online
                    Christian EhrlicherC Online
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    I think it jumps back to a default color (maybe text color).
                    I also took a look at the code but it's not that easy to understand so I can't provide a fix :(
                    But maybe @SGaist has some time ;)

                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                    Visit the Qt Academy at https://academy.qt.io/catalog

                    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