2 #include <QColorDialog>
6 QPushButton(parent), _alpha(allowAlpha), _setLabel(true), _bigIcons(false)
12 connect(
this, SIGNAL(clicked()),
this, SLOT(
pickColor()), Qt::QueuedConnection);
36 setText(
"Change color...");
39 const int w = 24, h =
_bigIcons ? 24 : 12;
40 QImage image(w, h, QImage::Format_RGB888);
41 QPainter painter(&image);
42 painter.setPen(Qt::NoPen);
43 painter.fillRect(0, 0, w, h, QColor(0, 0, 0));
45 painter.fillRect(1, 1, w / 2 - 1, h / 2 - 1, QColor(255, 255, 255));
46 painter.fillRect(w / 2, 1, w / 2 - 1, h / 2 - 1, QColor(192, 192, 192));
47 painter.fillRect(1, h / 2, w / 2 - 1, h / 2 - 1, QColor(192, 192, 192));
48 painter.fillRect(w / 2, h / 2, w / 2 - 1, h / 2 - 1, QColor(255, 255, 255));
50 painter.fillRect(1, 1, w - 2, h - 2,
_color);
51 setIcon(QIcon(QPixmap::fromImage(image)));
53 QString text = QString(
" (%1, %2, %3)").arg(
_color.red()).arg(
_color.green()).arg(
_color.blue());
55 text += QString(
", %4%").arg(QString::number(
_color.alphaF() * 100.,
'f', 0));
61 QColor newColor = QColorDialog::getColor(
_color,
this, QString(), QColorDialog::ColorDialogOptions(
_alpha ? QColorDialog::ShowAlphaChannel : 0));
62 if(newColor.isValid()){