普通
Qt提供了一个现成的QColorDialog类。
用法:
#include <QColorDialog>
QColor color = QColorDialog::getColor(Qt::white, this);
if(!color.isValid()){
     //点击 关闭 或 cancel 颜色无效
}else {
     ui->text->setText(color.name());//类似##ffff
     QRgb rgb = color.rgb();
     qDebug() << "rgb== " <<  qRed(rgb) << qGreen(rgb) << qBlue(rgb);
} 
缺点:不能直接显示颜色
进阶
用toolbutton来显示被选择的颜色

实现方法:
其实就是点击上面的button后,新建一个布局,往里遍历生成6*8个QToolButton,每个赋值一个颜色。点击后跟换上面的button的Icon(用Qpainter在QPixmap里画矩形,QRect这是绘制矩形框,根据需求设置不同的绘制方式,最后用 painter.drawPixmap往QRect里填)。



















