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. Set tableWidget item background color 60% red and 40% white
Forum Update on Monday, May 27th 2025

Set tableWidget item background color 60% red and 40% white

Scheduled Pinned Locked Moved Solved General and Desktop
drawbackgroundcolor
3 Posts 2 Posters 1.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
    qDebug
    wrote on last edited by
    #1

    Hello!

    I had an idea to visualize results displayed in a tableWidget by setting the background color. Lets say 60% voted for Pizza, i though it may be a nice idea to set the background like a progress bar to visualize it. At the moment i use QLinearGradient and it does look very nice.

    QLinearGradient linearGrad(QPointF(0, 25), QPointF(fillme, 25));
    linearGrad.setColorAt(0, Qt::red);
    linearGrad.setColorAt(1, Qt::white);
    
    ui->tableWidget->item(row, 8)->setBackground(linearGrad);
    

    The downside of QLinearGradient is this fluent transition between the colors, because there is no exact endpoint. I know, i kind of use it for the wrong reason, but so far i did fail to paint the background partial. I was able to set colors and images for the background but so far only for the whole background of the item, not the just 60% of it.

    Can i disable the color transition in QLinearGradient?
    Is there a better solution to my problem?

    Thank you!

    raven-worxR 1 Reply Last reply
    0
    • Q qDebug

      Hello!

      I had an idea to visualize results displayed in a tableWidget by setting the background color. Lets say 60% voted for Pizza, i though it may be a nice idea to set the background like a progress bar to visualize it. At the moment i use QLinearGradient and it does look very nice.

      QLinearGradient linearGrad(QPointF(0, 25), QPointF(fillme, 25));
      linearGrad.setColorAt(0, Qt::red);
      linearGrad.setColorAt(1, Qt::white);
      
      ui->tableWidget->item(row, 8)->setBackground(linearGrad);
      

      The downside of QLinearGradient is this fluent transition between the colors, because there is no exact endpoint. I know, i kind of use it for the wrong reason, but so far i did fail to paint the background partial. I was able to set colors and images for the background but so far only for the whole background of the item, not the just 60% of it.

      Can i disable the color transition in QLinearGradient?
      Is there a better solution to my problem?

      Thank you!

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

      @qDebug
      Do you mean something like this?

      QLinearGradient linearGrad(QPointF(0, 25), QPointF(fillme, 25));
      linearGrad.setColorAt(0, Qt::red);
      linearGrad.setColorAt(0.6, Qt::red);
      linearGrad.setColorAt(0.600000001, Qt::white);
      linearGrad.setColorAt(1, Qt::white);
      
      ui->tableWidget->item(row, 8)->setBackground(linearGrad);
      

      Not the most beautiful solution but it works.

      --- 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

      1 Reply Last reply
      3
      • Q Offline
        Q Offline
        qDebug
        wrote on last edited by
        #3

        Thank you!

        Just perfect! :D

        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