diff --git a/src/Gui/Widgets.cpp b/src/Gui/Widgets.cpp index 5163741e68..bf3fb836c9 100644 --- a/src/Gui/Widgets.cpp +++ b/src/Gui/Widgets.cpp @@ -622,7 +622,6 @@ struct ColorButtonP bool drawFrame{true}; bool allowTransparency{false}; bool modal{true}; - bool dirty{true}; }; } @@ -654,7 +653,6 @@ ColorButton::~ColorButton() void ColorButton::setColor(const QColor& c) { d->col = c; - d->dirty = true; update(); } @@ -677,7 +675,6 @@ void ColorButton::setPackedColor(uint32_t c) d->col.setGreenF(color.g); d->col.setBlueF(color.b); d->col.setAlphaF(color.a); - d->dirty = true; update(); } @@ -750,29 +747,26 @@ bool ColorButton::autoChangeColor() const */ void ColorButton::paintEvent (QPaintEvent * e) { - if (d->dirty) { - QSize isize = iconSize(); - QPixmap pix(isize); - pix.fill(palette().button().color()); - - QPainter p(&pix); - - int w = pix.width(); - int h = pix.height(); - p.setPen(QPen(Qt::gray)); - if (d->drawFrame) { - p.setBrush(d->col); - p.drawRect(2, 2, w - 5, h - 5); - } - else { - p.fillRect(0, 0, w, h, QBrush(d->col)); - } - setIcon(QIcon(pix)); - - d->dirty = false; - } - QPushButton::paintEvent(e); + + QSize isize = iconSize(); + QRectF colorRect(0, 0, isize.width(), isize.height()); + QPointF buttonCenter = rect().center(); + colorRect.moveCenter(buttonCenter); // move colorRect to center of button + + QPainter painter(this); + if(d->drawFrame) { + // frame is drawn on the outside of rectangle + // so we need to adjust to get same size as for non-frame button + constexpr qreal strokeWidth = 2; + colorRect.adjust(strokeWidth, strokeWidth, -strokeWidth, -strokeWidth); + painter.setBrush(d->col); + painter.setPen(Qt::gray); + painter.drawRect(colorRect); + } + else { + painter.fillRect(colorRect, d->col); + } } void ColorButton::showModeless()