Related Qusetions:
How to get widget background QColor
QWidget::palette().color(QWidget::backgroundRole())
There are at least 3 ways to solve the problem:
// 1st
QColor color = ui->toolButton->palette().color(QWidget::backgroundRole());
// 2nd
QColor color = ui->toolButton->palette().background().color();
// 3rd
QColor color = colorSetting = ui->toolButton->palette().color(QPalette::Window);
Update: sorry I have made some mistakes, both of the following ways work well.
Raw Qusetion:
I have tried
QColor color = ui->toolButton->palette().background().color();
and
QColor color = colorSetting = ui->toolButton->palette().color(QPalette::Window);
both got QColor(ARGB 1, 0.941176, 0.941176, 0.941176)
, not the right color I want.
The background color is set by editing mainwindow.ui
, change stylesheet of toolButton
to background-color: rgb(255, 170, 255);
and for pyQt, see here How to get the background color of a button or label (QPushButton, QLabel) in PyQt