Weird drawPath problem
-
So I have this problem: I designed a gauge that works almost always. In some environments the indicator is not shown. In the picture, the top gauge is correct, the bottom is wrong.
I attach the code that draws the indicator (needle).
In debug mode is working (of course...). In release, sometimes works, other times does not. Even in the same window, as in the picture.
Changing execution mode to Win 7 compatibility makes it work.
Executing with admin privilege makes it work.
void Gauge::drawNeedleShort (QColor color) { QPainter p(this); p.setRenderHint(QPainter::Antialiasing); const float nedR = (extR+intR)/2; const float nR = intR*0.9; const float ncA = 4; QPainterPath needle; needle.moveTo(cX+nedR*cosfD(mAngle),cY-nedR*sinfD(mAngle)); needle.lineTo(cX+nR*cosfD(mAngle+ncA),cY-nR*sinfD(mAngle+ncA)); needle.arcTo(cX-nR,cY-nR,2*nR,2*nR,mAngle+ncA,-2*ncA); needle.closeSubpath(); p.setPen(color); p.setBrush(QBrush(color)); p.drawPath(needle); }
-
How do you call drawNeedleShort()? Hopefully only within the paintEvent().
-
@Christian-Ehrlicher said in Weird drawPath problem:
How do you call drawNeedleShort()? Hopefully only within the paintEvent().
Exactly, here it is the paintEvent. As you can note also the drawRange is not working in the bottom picture: the green sector below the indicator is not shown. drawQuadrant and drawTicks seem work every time.
void Gauge::paintEvent(QPaintEvent *event) { drawQuadrant(); QColor drawColor=QWidget::palette().color(QWidget::foregroundRole()); drawRange(); drawNeedleShort(drawColor); drawTicks(); }
-
@Landolfi said in Weird drawPath problem:
Comes out there was an uninitialized variable that prevent drawing. It seems that IDE always initializes memory with some value.
Hi,
No, the IDE as nothing to do with that. If you don't explicitly initialize your variables with a value, they will contain garbage that may or may not have any sense.