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

How to color QListWidgetItem

Scheduled Pinned Locked Moved General and Desktop
5 Posts 4 Posters 27.5k 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.
  • E Offline
    E Offline
    endla.ravi
    wrote on last edited by
    #1

    hi..

    how can we give colors to QListWidgetItem

    This is the code I have..

    Suppose ,i Want to give green to the QListWidgetItem,how can I do it..
    @

    QListWidgetItem *x=new QListWidgetItem(name,ui->listWidget);
    ui->listWidget->addItem(name);
    ui->listWidget->show();
    @

    Thanks in advance..

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      It's very simple:

      @
      QListWidgetItem* pItem =new QListWidgetItem("my text to display");
      pItem->setForeground(Qt::red); // sets red text
      pItem->setBackground(Qt::green); // sets green background
      ui->listWidget->addItem(pItem);
      ui->listWidget->show();
      @

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • E Offline
        E Offline
        endla.ravi
        wrote on last edited by
        #3

        gerolf thanks man..!!

        1 Reply Last reply
        0
        • Z Offline
          Z Offline
          zerg2011
          wrote on last edited by
          #4

          Hi

          And what if I need to color only part of QListWidgetItem ?

          "ABRACADABRA" - whole text in QListWidgetItem
          I want to color only "CAD" in red .

          Thanks.

          1 Reply Last reply
          0
          • G Offline
            G Offline
            goetz
            wrote on last edited by
            #5

            Have a look at this "forum thread":http://developer.qt.nokia.com/forums/viewthread/3314/, it's the same problem.

            http://www.catb.org/~esr/faqs/smart-questions.html

            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