Dynamically changing QLabel background-color
-
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;
}@ -
This might give some hints:
"Change background colours or QWidget":http://qt-project.org/wiki/How_to_Change_the_Background_Color_of_QWidget -
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);@