[LyX/master] PrefColors dialog shows transparent swatches correctly
Koji Yokota
yokota at lyx.org
Tue Jun 2 04:51:31 UTC 2026
commit 5d497f745bdc64d6858fba4e585df33f6a65d786
Author: Koji Yokota <yokota at lyx.org>
Date: Thu May 14 19:19:51 2026 +0900
PrefColors dialog shows transparent swatches correctly
---
src/frontends/qt/GuiPrefs.cpp | 35 +++++++++++++++++++++++++++++++++--
src/frontends/qt/GuiPrefs.h | 3 +++
2 files changed, 36 insertions(+), 2 deletions(-)
diff --git a/src/frontends/qt/GuiPrefs.cpp b/src/frontends/qt/GuiPrefs.cpp
index 8b89f7ec34..4cbce38a0b 100644
--- a/src/frontends/qt/GuiPrefs.cpp
+++ b/src/frontends/qt/GuiPrefs.cpp
@@ -4720,6 +4720,26 @@ ColorSwatchDelegate::ColorSwatchDelegate(QObject *parent)
: QStyledItemDelegate(parent), button_(new QPushButton)
{
pane_ = static_cast<PrefColors*>(parent);
+
+ // construct the background image of swatches
+ bg_pixmap_ = new QPixmap(pane_->swatch_width_, pane_->swatch_height_);
+ bg_pixmap_->fill(Qt::white);
+ QPainter painter(bg_pixmap_);
+ painter.setRenderHint(QPainter::Antialiasing);
+ QPolygon polygon;
+ polygon << QPoint(pane_->swatch_width_, 0)
+ << QPoint(0, pane_->swatch_height_)
+ << QPoint(pane_->swatch_width_, pane_->swatch_height_);
+ painter.setPen(QColor(Qt::black));
+ painter.setBrush(QColor(Qt::black));
+ painter.drawPolygon(polygon);
+ painter.end();
+}
+
+
+ColorSwatchDelegate::~ColorSwatchDelegate()
+{
+ delete bg_pixmap_;
}
@@ -4743,9 +4763,10 @@ void ColorSwatchDelegate::paint(QPainter *painter,
QColor color =
pane_->colorsTV_model_.data(index, Qt::DecorationRole).
value<QColor>();
- if (index.flags().testFlag(Qt::ItemIsEnabled))
+ if (index.flags().testFlag(Qt::ItemIsEnabled)) {
pixmap.fill(color);
- else
+ pixmap = mergePixmaps(&pixmap, bg_pixmap_);
+ } else
pixmap.fill(Qt::transparent);
style->drawItemPixmap(painter, opt.rect, Qt::AlignCenter, pixmap);
} else {
@@ -4755,6 +4776,16 @@ void ColorSwatchDelegate::paint(QPainter *painter,
}
+QPixmap ColorSwatchDelegate::mergePixmaps(QPixmap const *fg, QPixmap const *bg) const
+{
+ // make a copy to leave bg untouched
+ QPixmap merged(*bg);
+ QPainter painter(&merged);
+ painter.drawPixmap(0, 0, *bg);
+ painter.drawPixmap(0, 0, *fg);
+ return merged;
+}
+
} // namespace frontend
} // namespace lyx
diff --git a/src/frontends/qt/GuiPrefs.h b/src/frontends/qt/GuiPrefs.h
index ab67f69ebc..441adc81c3 100644
--- a/src/frontends/qt/GuiPrefs.h
+++ b/src/frontends/qt/GuiPrefs.h
@@ -735,12 +735,15 @@ class ColorSwatchDelegate : public QStyledItemDelegate
public:
ColorSwatchDelegate(QObject *parent = nullptr);
+ ~ColorSwatchDelegate();
void paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const override;
private:
+ QPixmap mergePixmaps(QPixmap const * fg, QPixmap const * bg) const;
PrefColors* pane_;
+ QPixmap* bg_pixmap_;
QFont font_;
// To give impression that a button is pressed, flip the direction of
More information about the lyx-cvs
mailing list