Problem in setting stylesheet
-
hello friends
i have a problem in setting stylesheet in buttons..supoose i write my code like that
@QPushButton *but[5][5];
for(int i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
but[i][j]=new QPushButton();but[i][j]->setStyleSheet("background-color:red;") }
}
@here the code is working fine and all array of buttons are setcolor to red,now when i try to implement the same code by using function means i send row and coloums positions to an functions and setcolor of that buttons in that function than it doesnt work..code i have used is
@QPushButton *but[5][5];
for(int i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
but[i][j]=new QPushButton();
setStyle(i,j);
}
}//function is
void setStyle(int irow,int icol)
{
but[irow][icol]->setStyleSheet("background-color:red;")
}
@but more or less if i set text in the button than its work means if i write like this
@void setStyle(int irow,int icol)
{
but[irow][icol]->setText("p"); //its work
}@so can anyone tell me why this happen..please suggest me..
regards
RahulEdit: moved to General and Desktop, as this has nothing to do with mobile; Andre
-
I tried to reproduce your problem using the example below, but the styleheet works for me and the buttons are red. Does the example below reproduce your problem? If not, can you modify it so that it does? Which version of Qt are you using and on which platform?
@#include <QtGui>
QPushButton *but[5][5];
void setStyle(int irow,int icol)
{
but[irow][icol]->setStyleSheet("background-color:red;");
but[irow][icol]->show();
}int main(int argc, char ** argv)
{
QApplication app(argc, argv);for(int i=0;i<5;i++) { for(int j=0;j<5;j++) { but[i][j]=new QPushButton(); setStyle(i,j);
}}
return app.exec();
}
@ -
Actually i am using qt1.1..in windows7 platform but why is not working..because if it can settext to the button than why it cant be setcolor to the button..please suggest me..
-
Do you mean that you are using Qt 4.7.1? Qt 1.1 did not have stylesheets...
Does the example I pasted above work for you? If it does work, can you change it so that it shows your problem? That will make it easier to pinpoint what the problem is. If my example does not work for you, can you try upgrading to Qt 4.7.3 to see if that helps?
-
enum CYCLE_STAGE {
enSTAGE_NONE,
enSTAGE_FLOW,
enSTAGE_SAFE,
enSTAGE_UNSAFE,
enSTAGE_FERTILE
};yeh i get the error but dont know how to solve it..actually inside the function where i use to setcolor in the button i used enum in switch case...once i removed the enum its setting color so what does it mean
@ switch (iStage)
{case enSTAGE_NONE: cellBut[iRow][iCol]->setStyleSheet("background-image: url(:/Images/but-active.png);"); if (iStrLength) cellBut[iRow][iCol]->setStyleSheet("background-image: url(:/Images/but-active-notes.png);"); else cellBut[iRow][iCol]->setStyleSheet("background-image: url(:/Images/but-active.png);"); break; case enSTAGE_FLOW: cellBut[iRow][iCol]->setStyleSheet("background-image: url(:/Images/but-active.png);"); if (iStrLength) cellBut[iRow][iCol]->setStyleSheet("background-image: url(:/Images/but-blue-notes.png);"); else cellBut[iRow][iCol]->setText("Flow"); //cellBut[iRow][iCol]->setStyleSheet("background-image: url(:/Images/but-blue.png);"); break; case enSTAGE_SAFE: cellBut[iRow][iCol]->setStyleSheet("background-image: url(:/Images/but-active.png);"); if (iStrLength) cellBut[iRow][iCol]->setStyleSheet("background-image: url(:/Images/but-green-notes.png);"); else cellBut[iRow][iCol]->setText("Safe"); // cellBut[iRow][iCol]->setStyleSheet("background-image: url(:/Images/but-green.png);"); break; case enSTAGE_UNSAFE: cellBut[iRow][iCol]->setStyleSheet("background-image: url(:/Images/but-active.png);"); if (iStrLength) cellBut[iRow][iCol]->setStyleSheet("background-image: url(:/Images/but-orange-notes.png);"); else cellBut[iRow][iCol]->setText("unsafe"); // cellBut[iRow][iCol]->setStyleSheet("background-image: url(:/Images/but-orange.png);"); break; case enSTAGE_FERTILE: cellBut[iRow][iCol]->setStyleSheet("background-image: url(:/Images/but-active.png);"); if (iStrLength) cellBut[iRow][iCol]->setStyleSheet("background-image: url(:/Images/but-red-notes.png);"); else cellBut[iRow][iCol]->setText("Fertile"); //cellBut[iRow][iCol]->setStyleSheet("background-image: url(:/Images/but-red.png);"); break; default: break; } return true;@
-
The fact that an enum is used in a switch case should not cause any problems per say. Can you post a stand alone, small example that shows the problem? That way, we can reproduce the problem and investigate what the cause can be.