Sorry, I wrote it on the fly. It should be:
Qt Code:
  1. p.setColor(QPalette::Window, Qt::green); // background
  2. p.setColor(QPalette::WindowText, Qt::magenta); // foreground (text)
To copy to clipboard, switch view to plain text mode 
PS. QPalette, QPalette::ColorRole