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

Trying to set color

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 598 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.
  • ManiRonM Offline
    ManiRonM Offline
    ManiRon
    wrote on last edited by
    #1

    I am trying to draw an arc when we slide the slider i will draw the arc with Red color . Now when i set the backgroud color of the ui to black the arc which i draw is not visible. My code:

    this->setStyleSheet("background-color:black;");
    //this->setBackgroundRole(QPalette::Foreground);
    QPainter p(this);
    QPen pen;
    pen.setWidth(10);
    pen.setColor(Qt::red);
    p.setPen(pen);
    
    p.setRenderHint(QPainter::Antialiasing);
    
    QRectF rectangle(ui->LB_Progress->x()-20, ui->LB_Progress->y()-20, 80.0, 80.0);
    //to understand these magic numbers, look drawArc method in Qt doc
     int startAngle = -(270 * 16);
     int spanAngle =-(progress * 360 * 16);
    
    p.drawArc(rectangle, startAngle, spanAngle);
    
    p.drawText(rectangle,Qt::AlignCenter,QString::number(progress*100)+" %");
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by SGaist
      #2

      Hi,

      Why are you using a stylesheet since you do the painting yourself ?
      Start by filling the widget in black and then paint the rest over it.

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

      ManiRonM 2 Replies Last reply
      2
      • SGaistS SGaist

        Hi,

        Why are you using a stylesheet since you do the painting yourself ?
        Start by filling the widget in black and then paint the rest over it.

        ManiRonM Offline
        ManiRonM Offline
        ManiRon
        wrote on last edited by ManiRon
        #3

        @SGaist said in Trying to set color:

        how to do that sir,
        I am not getting your point

        1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

          Why are you using a stylesheet since you do the painting yourself ?
          Start by filling the widget in black and then paint the rest over it.

          ManiRonM Offline
          ManiRonM Offline
          ManiRon
          wrote on last edited by
          #4

          @SGaist

          Sir i used something like this and it worked

           QPalette pal(this->palette());
           QColor color(Qt::black);
           pal.setColor (QPalette::Background, color);
           this->setAutoFillBackground (true);
           this->setPalette(pal);
          

          Instead of using stylesheet for filling background i used this type to fill my widget background.

          mrjjM 1 Reply Last reply
          0
          • ManiRonM ManiRon

            @SGaist

            Sir i used something like this and it worked

             QPalette pal(this->palette());
             QColor color(Qt::black);
             pal.setColor (QPalette::Background, color);
             this->setAutoFillBackground (true);
             this->setPalette(pal);
            

            Instead of using stylesheet for filling background i used this type to fill my widget background.

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @ManiRon
            Hi
            Since you already have a paintEvent,
            all you need to paint it black is
            p.setBrush(Qt::black);
            p.drawRect( rect () );

            1 Reply Last reply
            1

            • Login

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