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. Change color of QLCD??
QtWS25 Last Chance

Change color of QLCD??

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 4 Posters 3.5k Views
  • 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.
  • Q Offline
    Q Offline
    QFelix
    wrote on 22 Feb 2020, 18:33 last edited by aha_1980
    #1

    Hello,
    I want to change the color of the digits from QLCDNumber. How do I write this in Qt Creator?

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 22 Feb 2020, 18:41 last edited by
      #2

      Set a QPalette with the colors you want. QLcdNumber is using the Light, Dark color role and the one set with QWidget::foregroundRole()

      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
      5
      • M Offline
        M Offline
        mrjj
        Lifetime Qt Champion
        wrote on 23 Feb 2020, 12:47 last edited by
        #3

        Hi
        Welcome to the forums
        As @Christian-Ehrlicher says, you can do that with QPalette like

        // get the palette
        auto palette = ui->lcdNumber->palette();
        // foreground color
        palette.setColor(palette.WindowText, Qt::blue);
        // "light" border
        palette.setColor(palette.Light, QColor(255, 0, 0));
        // "dark" border
        palette.setColor(palette.Dark, QColor(0, 255, 0));
        // set the palette back
        ui->lcdNumber->setPalette(palette);
        

        alt text

        However, it looks best if you change to flat look
        ui->lcdNumber->setSegmentStyle(QLCDNumber::Flat );
        alt text

        Or matches the dark/light with the base color so the 'raised' look still works.

        Q 1 Reply Last reply 23 Feb 2020, 15:21
        3
        • M mrjj
          23 Feb 2020, 12:47

          Hi
          Welcome to the forums
          As @Christian-Ehrlicher says, you can do that with QPalette like

          // get the palette
          auto palette = ui->lcdNumber->palette();
          // foreground color
          palette.setColor(palette.WindowText, Qt::blue);
          // "light" border
          palette.setColor(palette.Light, QColor(255, 0, 0));
          // "dark" border
          palette.setColor(palette.Dark, QColor(0, 255, 0));
          // set the palette back
          ui->lcdNumber->setPalette(palette);
          

          alt text

          However, it looks best if you change to flat look
          ui->lcdNumber->setSegmentStyle(QLCDNumber::Flat );
          alt text

          Or matches the dark/light with the base color so the 'raised' look still works.

          Q Offline
          Q Offline
          QFelix
          wrote on 23 Feb 2020, 15:21 last edited by QFelix
          #4

          @mrjj What's the "ui" you're using? Can't find it in my code...

          And another question: I wrote a program with some pictures and so on, it's a racing game. I wahr to include QLCDNumber in this program to Show the score, but it doesn't works...

          A 1 Reply Last reply 23 Feb 2020, 15:25
          0
          • Q QFelix
            23 Feb 2020, 15:21

            @mrjj What's the "ui" you're using? Can't find it in my code...

            And another question: I wrote a program with some pictures and so on, it's a racing game. I wahr to include QLCDNumber in this program to Show the score, but it doesn't works...

            A Offline
            A Offline
            aha_1980
            Lifetime Qt Champion
            wrote on 23 Feb 2020, 15:25 last edited by
            #5

            @QFelix said in [SOLVED] Change color of QLCD??:

            @mrjj What's the "ui" you're using? Can't find it in my code...

            If you create your code with Qt designer, you typically have a member ui in your class where you reference all your UI widgets. If you add them programmatically, then just ignore this ;)

            Regards

            Qt has to stay free or it will die.

            1 Reply Last reply
            3
            • M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 23 Feb 2020, 15:29 last edited by
              #6

              @QFelix said in Change color of QLCD??:

              I wahr to include QLCDNumber in this program to Show the score, but it doesn't works...

              Hi
              How did yo use it ?
              It should just work like any other widget you used.
              But without some code , its hard to guess at what went wrong.

              1 Reply Last reply
              0

              1/6

              22 Feb 2020, 18:33

              • Login

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