kyotishi
15th April 2013, 14:51
Hi all,
I am working on a QT GUI application, I receive data from a microcontroller through serial at 5Hz and I am updating the GUI accordingaly
I use QLabel to display received values.
everything works fine, except that I want to change the text color of the QLabel when a value exceeds a certain limit, I have one hundered value to updated and using
stylesheet makes the GUI VERY SLOOOW, and if I use QPalette then there is no effect at all (the color is not changed)
here is my two version of the code
//using Stylesheets:
void GUI::checkLimits(double max, float value, QLabel * label){
if ((value > max)
{
label->setStyleSheet(QString::fromUtf8("color: rgb(255, 0, 0);\n"
""));
}else{
label->setStyleSheet(QString::fromUtf8("color: rgb(0, 255, 255);\n"
""));
}
}
//using QPalette:
void GUI::checkLimits(double max, float value, QLabel * label){
QPalette pal = label->palette ();
if ((value > max)
{
pal->setColor(QPalette::WindowText, Qt::red);
}else{
pal->setColor(QPalette::WindowText, Qt::white);
}
label->setPalette (pal);
label->setAutoFillBackground(true);
}
//then call the function for each Qlabel:
//update the measurements as read from the PMU
void Display::updateData()
{
double max1 = 3.3;
double max2 = 5.5;
double max3 = 7.7;
//value 1
//get the received value
value1 = (receivedData->rec1);
//check if the received value exceeds the max allowed value
checkLimits(max1 ,value1, iuGUI->Qlabel1);
//change the text of the label
iuGUI->Qlabel1->setText(QString::number(value));
//value 2
value2 = (receivedData->rec2);
checkLimits(max2 ,value2, iuGUI->Qlabel2);
iuGUI->Qlabel2->setText(QString::number(value));
//value 3
value3 = (receivedData->rec3);
checkLimits(max3 ,value3, iuGUI->Qlabel3);
iuGUI->Qlabel3->setText(QString::number(value));
//etc....repeat the same for all the values...100!!
}
I am using QT 4.7 and running on Windows 7
I am working on a QT GUI application, I receive data from a microcontroller through serial at 5Hz and I am updating the GUI accordingaly
I use QLabel to display received values.
everything works fine, except that I want to change the text color of the QLabel when a value exceeds a certain limit, I have one hundered value to updated and using
stylesheet makes the GUI VERY SLOOOW, and if I use QPalette then there is no effect at all (the color is not changed)
here is my two version of the code
//using Stylesheets:
void GUI::checkLimits(double max, float value, QLabel * label){
if ((value > max)
{
label->setStyleSheet(QString::fromUtf8("color: rgb(255, 0, 0);\n"
""));
}else{
label->setStyleSheet(QString::fromUtf8("color: rgb(0, 255, 255);\n"
""));
}
}
//using QPalette:
void GUI::checkLimits(double max, float value, QLabel * label){
QPalette pal = label->palette ();
if ((value > max)
{
pal->setColor(QPalette::WindowText, Qt::red);
}else{
pal->setColor(QPalette::WindowText, Qt::white);
}
label->setPalette (pal);
label->setAutoFillBackground(true);
}
//then call the function for each Qlabel:
//update the measurements as read from the PMU
void Display::updateData()
{
double max1 = 3.3;
double max2 = 5.5;
double max3 = 7.7;
//value 1
//get the received value
value1 = (receivedData->rec1);
//check if the received value exceeds the max allowed value
checkLimits(max1 ,value1, iuGUI->Qlabel1);
//change the text of the label
iuGUI->Qlabel1->setText(QString::number(value));
//value 2
value2 = (receivedData->rec2);
checkLimits(max2 ,value2, iuGUI->Qlabel2);
iuGUI->Qlabel2->setText(QString::number(value));
//value 3
value3 = (receivedData->rec3);
checkLimits(max3 ,value3, iuGUI->Qlabel3);
iuGUI->Qlabel3->setText(QString::number(value));
//etc....repeat the same for all the values...100!!
}
I am using QT 4.7 and running on Windows 7