1. 程式人生 > 其它 >Qt基礎-設定按鈕背景顏色

Qt基礎-設定按鈕背景顏色

技術標籤:Qt基礎qt

使用QPalette無法設定,可以使用樣式表:

QColor color = QColorDialog::getColor(Qt::black, this, "請選擇顏色");

int r = 0, g = 0, b = 0;
color.getRgb(&r,&g,&b);
ui.btn->setStyleSheet(QString("background-color: rgb(%1,%2,%3)").arg(r).arg(g).arg(b));

在這裡插入圖片描述