Results 1 to 2 of 2

Thread: Chameleon

  1. #1
    Join Date
    Dec 2007
    Location
    Brazil
    Posts
    61
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Chameleon

    The code below allows me to change the color of QTextEdit when the function is called.

    Qt Code:
    1. void DetonSis::colorEdit(QTextEdit *color)
    2. {
    3. QPalette pal, pal2;
    4. pal.setColor(QPalette::Base, QColor(qrand() % 256, qrand() % 256, qrand() % 256));
    5. pal2.setColor(QPalette::Base, Qt::white);
    6.  
    7. for(int i = 0; i < listEdit.size(); ++i)
    8. listEditor[i]->setPalette(pal2);
    9. color->setPalette(pal);
    10. }
    To copy to clipboard, switch view to plain text mode 

    What I want is to limit the function
    Qt Code:
    1. QColor(qrand() % 256, qrand() % 256, qrand() % 256)
    To copy to clipboard, switch view to plain text mode 
    for only three known colors. Any idea?
    Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Chameleon

    What's about
    Qt Code:
    1. QList<QColor> list;
    2. // fill the list with the colors you like
    3. QColor randomColor = list.at(qrand() % list.count());
    To copy to clipboard, switch view to plain text mode 
    Also your function looks very odd. pal1 isn't used and the color pointer seems useless...

  3. The following user says thank you to Lykurg for this useful post:

    jaca (3rd December 2011)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.