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. Dynamically changing QLabel background-color

Dynamically changing QLabel background-color

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

    Hi everyone!! I m newbee on the QT platform. :) now I have actually a problem on QLabel. Problem is that QLabel background-color is not changed as dynamically on the my gui which is designed. Firstly I have added 3 slider(for RGB in range(0-255)) to gui and then QLabel. in side of programming I use together with QPalette on the QT 5.3 release Result in I wanted a user to change QLabel background-color dynamically. Althought I research this problem I could not find a convenient way to solve it. I hope you can help to me :) as you 're senior Coder. I have also added below sourcefile and" Code "snippet":http://uploaded.net/file/g6axidqj.

    //also I use uchar[3] array for RGB Values so that I m going to able to change the color of QLabel according to position of slider(as a mutual exclusion ) in the Next time.

    @MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);

    palet = ui->Color_label->palette();
    

    }

    void MainWindow::on_Green_slider_2_valueChanged(int value)
    {
    ui->Green_val_lcd_2->display(value);
    palet.setColor(ui->Color_label->backgroundRole(),QColor(rgb_val_uchar[0],value,rgb_val_uchar[2]));
    ui->Color_label->setPalette(palet);
    rgb_val_uchar[1]=value;
    }@

    I believe Allah(c.c) and His messenger prophet Muhammed(S.a.v) _C*_C*C*

    1 Reply Last reply
    0
    • JeroentjehomeJ Offline
      JeroentjehomeJ Offline
      Jeroentjehome
      wrote on last edited by
      #2

      This might give some hints:
      "Change background colours or QWidget":http://qt-project.org/wiki/How_to_Change_the_Background_Color_of_QWidget

      Greetz, Jeroen

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mushack
        wrote on last edited by
        #3

        Hi Breeder! very thanks for your reply. now I found a solution while I research in net. it seems that I should had added below code line while QPalette is created.
        @ui->color_label->setAutoFillBackground(true);@

        this link says " that ":http://qt-project.org/forums/viewthread/4291

        in short:

        @title->setAutoFillBackground(true); // IMPORTANT!
        QPalette pal = title->palette();
        pal.setColor(QPalette::Window, QColor(Qt::black));
        title->setPalette(pal);@

        I believe Allah(c.c) and His messenger prophet Muhammed(S.a.v) _C*_C*C*

        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