//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
){
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!!
}
//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!!
}
To copy to clipboard, switch view to plain text mode
Bookmarks