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 change the color of a QLabel?
Qt 6.11 is out! See what's new in the release blog

How to change the color of a QLabel?

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

    I know this is a basic question. But I searched the net and tried many ways. None of them are working.

    I tried

    QPalette color;
    color.setColor(QPalette::WindowText, Qt::red);

    ui->qLabel->setText("<font color='red'>Text</font>");

    ui->qLabel->setStyleSheet("QLabel { color : red; }");

    raven-worxR 1 Reply Last reply
    0
    • M MasterBlade

      I know this is a basic question. But I searched the net and tried many ways. None of them are working.

      I tried

      QPalette color;
      color.setColor(QPalette::WindowText, Qt::red);

      ui->qLabel->setText("<font color='red'>Text</font>");

      ui->qLabel->setStyleSheet("QLabel { color : red; }");

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @MasterBlade
      the last 2 approaches definitely work.
      If they are not then the issue is somewhere else in your code.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      M 1 Reply Last reply
      2
      • dheerendraD Offline
        dheerendraD Offline
        dheerendra
        Moderators Qt Champions 2024 Qt Champions 2022 Qt Champions 2017
        wrote on last edited by
        #3

        use - label.setStyleSheet("background:red");

        Dheerendra
        @Community Service
        Certified Qt Specialist
        https://www.pthinks.com

        1 Reply Last reply
        0
        • raven-worxR raven-worx

          @MasterBlade
          the last 2 approaches definitely work.
          If they are not then the issue is somewhere else in your code.

          M Offline
          M Offline
          MasterBlade
          wrote on last edited by
          #4

          @raven-worx @dheerendra

          I figured it out somehow by using

          QPalette color;
          color.setColor(QPalette::ButtonText, Qt::red);

          Thanks for the help!

          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