简体   繁体   中英

How to display a QColor from QColorDialog in a widget?

I have a ColorPicker dialog like:

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

The result of that I put in a QLineEdit via color.name() , eg #ff0000 . I would like to display that color as the red field in this example, too

在此处输入图片说明

I don't know what Widget to pick for this to display? QPicture?

I enhanced this answer here . If you already grabbed the QColor in color , you can try for a QLabel* label :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM