View Issue Details

IDProjectCategoryView StatusLast Update
0035568LazarusWidgetsetpublic2020-04-04 16:59
ReporterCudaText man Assigned ToZeljan Rikalo  
PrioritynormalSeverityminorReproducibilityalways
Status assignedResolutionreopened 
Product Version2.1 (SVN) 
Summary0035568: Qt: Canvas.Ellipse paints little incorrect
DescriptionI see it on Qt4 [cannot test Qt5, cannot install big runtime, so just change demo project and test it].
Run demo.
On gkt2: circle and cross - are painted symmetrical. circle is painted INSIDE square.
On qt4: circle and cross - are NOT symmetrical.
TagsNo tags attached.
Fixed in Revision61220
LazTarget-
WidgetsetQT, QT5
Attached Files

Activities

CudaText man

2019-05-12 14:20

reporter  

tst-qt-circle.zip (3,049 bytes)

CudaText man

2019-05-12 14:21

reporter  

qt-demo.png (2,360 bytes)   
qt-demo.png (2,360 bytes)   

Zeljan Rikalo

2019-05-13 14:09

developer   ~0116162

Seem that giuliano broken ellipse() in r47651, don't know if radialPie() is broken also by his commit.

Zeljan Rikalo

2019-05-13 15:05

developer   ~0116165

Please test and close if ok. Note that Qt5 should not be touched , because offset by -1 shows gap at the end of rect from example.
Yet I don't know if RadialPie() is correct since Giuliano removed offsets from both routines in r47651 without logged issue about it.

CudaText man

2019-05-13 15:54

reporter   ~0116168

I still see that circle is not symmetrical. picture.
qt-after fix.png (1,822 bytes)   
qt-after fix.png (1,822 bytes)   

Zeljan Rikalo

2019-05-13 17:07

developer   ~0116171

That's all I can do under Qt. Ellipse is painted by Qt ..... I'll revert r61220 in that case ... probably something related to pen

Zeljan Rikalo

2019-05-13 17:27

developer   ~0116172

I've reverted 61220 , so no offset. When antialising is ON and NSize eg 400 it is much easier to see that pixel drawing is correct, but somehow QPen drawing is blurred at the right/bottom.

CudaText man

2019-05-13 22:46

reporter   ~0116178

How can I help you?

Zeljan Rikalo

2019-05-14 08:24

developer   ~0116190

It's Qt bug, not lclqt one.
https://bugreports.qt.io/browse/QTBUG-5587
https://bugreports.qt.io/browse/QTBUG-1292
There's some kind of workaround at QTBUG-1292, so I'll try to fix it somehow.

Zeljan Rikalo

2019-05-14 08:40

developer   ~0116194

Here is "workaround" from QTBUG-1292 issue, drawing ellipse with QPainterPath and QPolygon, but as I can see there's no difference ....
qtdrawellipsewithpolygon.diff (1,131 bytes)   
Index: lcl/interfaces/qt/qtwinapi.inc
===================================================================
--- lcl/interfaces/qt/qtwinapi.inc	(revision 61222)
+++ lcl/interfaces/qt/qtwinapi.inc	(working copy)
@@ -1508,11 +1508,21 @@
 function TQtWidgetSet.Ellipse(DC: HDC; x1, y1, x2, y2: Integer): Boolean;
 var
   R: TRect;
+  APath: QPainterPathH;
+  APolygon: QPolygonFH;
 begin
   if not IsValidDC(DC) then Exit(False);
   R := NormalizeRect(Rect(X1, Y1, X2, Y2));
   if IsRectEmpty(R) then Exit(True);
-  TQtDeviceContext(DC).drawEllipse(R.Left, R.Top, R.Right - R.Left, R.Bottom - R.Top);
+  APath := QPainterPath_create();
+  APolygon := QPolygonF_create();
+  QPainterPath_addEllipse(APath, R.Left, R.Top, R.Right - R.Left, R.Bottom - R.Top);
+  QPainterPath_toFillPolygon(APath, APolygon, QPainter_transform(TQtDeviceContext(DC).Widget));
+  QPainterPath_closeSubpath(APath);
+  QPainter_drawPolygon(TQtDeviceContext(DC).Widget, APolygon);
+  // TQtDeviceContext(DC).drawEllipse(R.Left, R.Top, R.Right - R.Left, R.Bottom - R.Top);
+  QPainterPath_destroy(APath);
+  QPolygonF_destroy(APolygon);
   Result := True;
 end;
 
qtdrawellipsewithpolygon.diff (1,131 bytes)   

Zeljan Rikalo

2020-04-04 16:59

developer   ~0121902

I've attached workaround for more precise ellipse draw, please test and give feedback (Qt5 only !!) - ellipse_workaround.diff
ellipse_workaround.diff (1,018 bytes)   
Index: qtwinapi.inc
===================================================================
--- qtwinapi.inc	(revision 62884)
+++ qtwinapi.inc	(working copy)
@@ -1475,12 +1475,20 @@
 function TQtWidgetSet.Ellipse(DC: HDC; x1, y1, x2, y2: Integer): Boolean;
 var
   R: TRect;
+  ARectF: QRectFH;
+  APenWidthF: QReal;
 begin
   if not IsValidDC(DC) then Exit(False);
   R := NormalizeRect(Rect(X1, Y1, X2, Y2));
   if IsRectEmpty(R) then Exit(True);
 
-  TQtDeviceContext(DC).drawEllipse(R.Left, R.Top, R.Right - R.Left, R.Bottom - R.Top{ - 1});
+  APenWidthF := QPen_widthF(QPainter_pen(TQtDeviceContext(DC).Widget));
+  if APenWidthF = 0 then
+    APenWidthF := 1;
+  ARectF := QRectF_Create(R.Left + (APenWidthF / 2), R.Top + (APenWidthF / 2), R.Right - R.Left - APenWidthF, R.Bottom - R.Top - APenWidthF);
+  QPainter_drawEllipse(TQtDeviceContext(DC).Widget, ARectF);
+  // TQtDeviceContext(DC).drawEllipse(R.Left, R.Top, R.Right - R.Left, R.Bottom - R.Top{ - 1});
+  QRectF_destroy(ARectF);
   Result := True;
 end;
 
ellipse_workaround.diff (1,018 bytes)   

Issue History

Date Modified Username Field Change
2019-05-12 14:20 CudaText man New Issue
2019-05-12 14:20 CudaText man File Added: tst-qt-circle.zip
2019-05-12 14:21 CudaText man File Added: qt-demo.png
2019-05-12 19:34 Zeljan Rikalo Assigned To => Zeljan Rikalo
2019-05-12 19:34 Zeljan Rikalo Status new => assigned
2019-05-13 14:09 Zeljan Rikalo Note Added: 0116162
2019-05-13 15:05 Zeljan Rikalo Status assigned => resolved
2019-05-13 15:05 Zeljan Rikalo Resolution open => fixed
2019-05-13 15:05 Zeljan Rikalo Fixed in Revision => 61220
2019-05-13 15:05 Zeljan Rikalo LazTarget => -
2019-05-13 15:05 Zeljan Rikalo Widgetset QT, QT5 => QT, QT5
2019-05-13 15:05 Zeljan Rikalo Note Added: 0116165
2019-05-13 15:54 CudaText man File Added: qt-after fix.png
2019-05-13 15:54 CudaText man Note Added: 0116168
2019-05-13 15:55 CudaText man Status resolved => assigned
2019-05-13 15:55 CudaText man Resolution fixed => reopened
2019-05-13 17:07 Zeljan Rikalo Status assigned => feedback
2019-05-13 17:07 Zeljan Rikalo Note Added: 0116171
2019-05-13 17:27 Zeljan Rikalo Note Added: 0116172
2019-05-13 22:46 CudaText man Note Added: 0116178
2019-05-13 22:46 CudaText man Status feedback => assigned
2019-05-14 08:24 Zeljan Rikalo Note Added: 0116190
2019-05-14 08:40 Zeljan Rikalo File Added: qtdrawellipsewithpolygon.diff
2019-05-14 08:40 Zeljan Rikalo Note Added: 0116194
2020-04-04 16:59 Zeljan Rikalo File Added: ellipse_workaround.diff
2020-04-04 16:59 Zeljan Rikalo Note Added: 0121902