2015-08-25 44 views
1

我有一個顏色拾取對話框,如:如何在小部件中顯示QColorDialog中的QColor?

QColor color = QColorDialog::getColor(Qt::black, this, "Pick a color", QColorDialog::DontUseNativeDialog); 

我把一個QLineEdit的通過color.name(),例如那結果#ff0000。 我想顯示顏色爲紅色區域在這個例子中,也

enter image description here

我不知道是什麼的Widget爲此選取顯示? QPicture?

+0

可以使用QFrame – PYPL

回答

1

我增強了這個答案here。如果你已經搶到的QColor在color,你可以嘗試爲QLabel* label

QPalette palette = label->palette(); 
palette.setColor(label->backgroundRole(), color);  
label->setAutoFillBackground(true); 
label->setPalette(palette); 
相關問題