Hi, all,
I want to _get_ the color of a standard checked button.

The purpose is to change the background of an adjacent widget to match the checked color.
I read sufficiently about palettes and style sheets, and made numerous forum searches with combinations of keywords.
After getting nowhere I repeated some tests with several brute-force combinations:

Qt Code:
  1. ui->myButton->setChecked(true); // ensure it is in the correct state
  2.  
  3. // no effect:
  4. // copy myButton color
  5. // overwrite myWidget background color
  6.  
  7. // no effect:
  8. // copy myButton palette
  9. // overwrite myWidget palette
  10.  
  11. // At this point I wasn't sure whether the reading or writing doesn't work.
  12. // Style sheets are always preferred (although this is a very simple requirement)
  13. // so I'll use it based on some examples and other answers.
  14.  
  15. QColor c;
  16. c = ui->myButton->palette().color(QPalette::Active, QPalette::Button);
  17. // or c = ui->myButton->palette().color(QPalette::Active, QPalette::Window);
  18. // or c = ui->myButton->palette().color(QPalette::Active, QPalette::Base);
  19. // or ...any other ColorRole
  20.  
  21. QString s = QString("background-color: rgb(%1,%2,%3)")
  22. .arg(c.red()).arg(c.green()).arg(c.blue());
  23. ui->myWidget->setStyleSheet(s);
  24. ui->myWidget->setAutoFillBackground(true);
  25. ui->myWidget->show();
To copy to clipboard, switch view to plain text mode 

Depending on which ColorRole, the widget background changes, so reading the palette color and setting the style sheet work.
Any ideas how to get the clicked color?
Scott