Home > Back-end >  QPainter draw text gray edge
QPainter draw text gray edge

Time:02-22

QPainter is used to change the text when plotted on a QImage, found a little bit of text edge gray edge, but when using QWidget to draw, but not the gray edge
Below is I'm looking forward to the effect of the

But this is the actual effect of drawing after

Please answer how to solve this problem

CodePudding user response:

This is I use the code
 
QPainter painter (& amp; M_canvasImage);
Painter. SetRenderHints (QPainter: : TextAntialiasing | QPainter: : SmoothPixmapTransform);
Painter. SetBrush (Qt: : NoBrush);
Painter. The setFont (item - & gt; The font ());
Painter. SetPen (QPen (QColor (Qt: : red)));
The QRect textRect (the rect);
Painter. DrawText (textRect, this is the word "test");

CodePudding user response:

Reference of this article: https://blog.csdn.net/yejin_tianming/article/details/105113668? Ops_request_misc=% 257 b % 2522 request 255 fid 253 a % 2522161388220216780269875918% % 2522% % 2522% % 252 c 2522 SCM 253 a % % 2522% 252220140713.130102334.. % 2522% 257 d & amp; Request_id=161388220216780269875918 & amp; Biz_id=0 & amp; Utm_medium=distribute. Pc_search_result. None - task - blog - 2 ~ ~ sobaiduend ~ all default - 2-105113668. Pc_search_result_cache & amp; Utm_term=setCompositionMode
Try, for reference:
 QPainter painter (& amp; M_canvasImage); 
Painter. SetRenderHints (QPainter: : TextAntialiasing | QPainter: : SmoothPixmapTransform);
Painter. SetCompositionMode (QPainter: : CompositionMode_DestinationOver);//image overlay mode
Painter. SetBrush (Qt: : NoBrush);
Painter. The setFont (item - & gt; The font ());
Painter. SetPen (QPen (QColor (Qt: : red)));
The QRect textRect (the rect);
Painter. DrawText (textRect, this is the word "test");
  • Related