Odd behaviour with QPen/QColor
-
I have a widget that is displayed on top of another widget (imageView), and has the following attributes set in the ctor:
setAttribute(Qt::WA_TransparentForMouseEvents); setAttribute(Qt::WA_NoSystemBackground); setAttribute(Qt::WA_WState_ExplicitShowHide);
This code in its paintEvent:
QPainter painter(this); QColor colour{ QColorConstants::Cyan }; colour.setAlpha(128); QPen pen(colour, 1.0); if (pt1_ != pt2_) { QPointF p1 = imageView->imageToScreen(pt1_); if (p1.x() < 0.5) p1.rx() = 0.5; if (p1.y() < 0.5) p1.rx() = 0.5; QPointF p2 = imageView->imageToScreen(pt2_); if (p2.x() < 0.5) p2.rx() = 0.5; p2.ry()--; QPointF p3 = imageView->imageToScreen(pt3_); p3.rx()--; p3.ry()--; QPointF p4 = imageView->imageToScreen(pt4_); if (p4.x() < 0.5) p4.rx() = 0.5; p4.ry()--; painter.drawLine(p1, p2); painter.drawLine(p2, p3); painter.drawLine(p3, p4); painter.drawLine(p4, p1); }
mostly works fine except that the line drawn is white and not semi-transparent???
Am I missing something obvious here?
Thanks
David -
I have a widget that is displayed on top of another widget (imageView), and has the following attributes set in the ctor:
setAttribute(Qt::WA_TransparentForMouseEvents); setAttribute(Qt::WA_NoSystemBackground); setAttribute(Qt::WA_WState_ExplicitShowHide);
This code in its paintEvent:
QPainter painter(this); QColor colour{ QColorConstants::Cyan }; colour.setAlpha(128); QPen pen(colour, 1.0); if (pt1_ != pt2_) { QPointF p1 = imageView->imageToScreen(pt1_); if (p1.x() < 0.5) p1.rx() = 0.5; if (p1.y() < 0.5) p1.rx() = 0.5; QPointF p2 = imageView->imageToScreen(pt2_); if (p2.x() < 0.5) p2.rx() = 0.5; p2.ry()--; QPointF p3 = imageView->imageToScreen(pt3_); p3.rx()--; p3.ry()--; QPointF p4 = imageView->imageToScreen(pt4_); if (p4.x() < 0.5) p4.rx() = 0.5; p4.ry()--; painter.drawLine(p1, p2); painter.drawLine(p2, p3); painter.drawLine(p3, p4); painter.drawLine(p4, p1); }
mostly works fine except that the line drawn is white and not semi-transparent???
Am I missing something obvious here?
Thanks
David@Perdrix said in Odd behaviour with QPen/QColor:
QPen pen(colour, 1.0);
You're not using pen anywhere as far as I can see...
-
@Perdrix said in Odd behaviour with QPen/QColor:
QPen pen(colour, 1.0);
You're not using pen anywhere as far as I can see...
-
S SGaist has marked this topic as solved on