PDA

View Full Version : Chameleon



jaca
1st December 2011, 16:15
The code below allows me to change the color of QTextEdit when the function is called.


void DetonSis::colorEdit(QTextEdit *color)
{
QPalette pal, pal2;
pal.setColor(QPalette::Base, QColor(qrand() % 256, qrand() % 256, qrand() % 256));
pal2.setColor(QPalette::Base, Qt::white);

for(int i = 0; i < listEdit.size(); ++i)
listEditor[i]->setPalette(pal2);
color->setPalette(pal);
}

What I want is to limit the function
QColor(qrand() % 256, qrand() % 256, qrand() % 256) for only three known colors. Any idea?
Thanks

Lykurg
1st December 2011, 16:49
What's about
QList<QColor> list;
// fill the list with the colors you like
QColor randomColor = list.at(qrand() % list.count());
Also your function looks very odd. pal1 isn't used and the color pointer seems useless...