Skip to content

Commit fbd55a3

Browse files
committed
fix: updatePanelMask QPainter warnings log spam caused by hidden widgets
Fixes these warnings: QPainter::begin: Paint device returned engine == 0, type: 2 QPainter::setRenderHint: Painter must be active to set rendering hints QPainter::setBrush: Painter not active QPainter::setPen: Painter not active QPainter::drawPath: Painter not active
1 parent 979699d commit fbd55a3

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

package/contents/ui/main.qml

+3-1
Original file line numberDiff line numberDiff line change
@@ -1176,7 +1176,9 @@ PlasmoidItem {
11761176

11771177
function updateMask() {
11781178
if (panelColorizer === null || !borderRec) return
1179-
// console.error("updateMask()", widgetName)
1179+
// don't try to create a mask if the widget is not visible
1180+
// for example with PlasmaCore.Types.HiddenStatus
1181+
if (borderRec.width <= 0 || borderRec.height <= 0) return
11801182
position = Utils.getGlobalPosition(borderRec, panelElement)
11811183
panelColorizer.updatePanelMask(
11821184
maskIndex,

plugin/panelcolorizer.cpp

+19-10
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,25 @@ PanelColorizer::PanelColorizer(QObject *parent) : QObject(parent) {}
1818
void PanelColorizer::updatePanelMask(int index, QRectF rect, double topLeftRadius, double topRightRadius,
1919
double bottomLeftRadius, double bottomRightRadius, QPointF offset,
2020
int radiusCompensation, bool visible) {
21-
// qDebug() << "updatePanelMask x:" << offset.x() << " y:" << offset.y() << " W:" << rect.width()
22-
// << " H:" << rect.height();
21+
if (rect.isEmpty()) {
22+
qWarning() << "PanelColorizer::updatePanelMask: Invalid rect: " << rect;
23+
return;
24+
}
25+
26+
QPixmap pixmap(rect.size().toSize());
27+
pixmap.fill(Qt::transparent);
28+
// Draw the QPainterPath onto the QPixmap for antialiasing
29+
QPainter painter(&pixmap);
30+
if (!painter.isActive()) {
31+
qWarning() << "PanelColorizer::updatePanelMask: QPainter is not active";
32+
return;
33+
}
34+
painter.setRenderHint(QPainter::Antialiasing);
35+
painter.setBrush(Qt::black);
36+
// no border
37+
painter.setPen(Qt::NoPen);
38+
39+
// HACK: make the kornes less visible
2340
topLeftRadius += (topLeftRadius != 0) ? radiusCompensation : 0;
2441
topRightRadius += (topRightRadius != 0) ? radiusCompensation : 0;
2542
bottomLeftRadius += (bottomLeftRadius != 0) ? radiusCompensation : 0;
@@ -35,14 +52,6 @@ void PanelColorizer::updatePanelMask(int index, QRectF rect, double topLeftRadiu
3552
path.lineTo(rect.topLeft() + QPointF(0, topLeftRadius));
3653
path.quadTo(rect.topLeft(), rect.topLeft() + QPointF(topLeftRadius, 0));
3754

38-
QPixmap pixmap(rect.size().toSize());
39-
pixmap.fill(Qt::transparent);
40-
// Draw the QPainterPath onto the QPixmap for antialiasing
41-
QPainter painter(&pixmap);
42-
painter.setRenderHint(QPainter::Antialiasing);
43-
painter.setBrush(Qt::black);
44-
// no border
45-
painter.setPen(Qt::NoPen);
4655
painter.drawPath(path);
4756

4857
QRegion region = QRegion(pixmap.createMaskFromColor(Qt::transparent));

0 commit comments

Comments
 (0)