简体   繁体   English

如何用QPainter绘制焦点图标

[英]How to draw focus icon with QPainter

In the project I am working now we already have the left arrow(which can be seen left bottom corner) drawn with QPaint the code is like : 在我正在工作的项目中,我们已经用QPaint绘制了左箭头(可以在左下角看到),代码如下:

const qreal x1 = left ? (rect.left() + 19) : (rect.right() - 19);
const qreal x2 = left ? (rect.left() + 12) : (rect.right() - 12);
const qreal y2 = rect.y() + rect.height() / 2.0;
const qreal y1 = y2 - 8;
const qreal y3 = y2 + 8;
painter->setPen(QPen(InternalStuff::Instance()->GetColor(ILMCTheme::ColorIconInfoBarArrow), 3, Qt::SolidLine, Qt::RoundCap));
const QVector<QPointF> points = QVector<QPointF>() << QPointF(x1, y1) << QPointF(x2, y2) << QPointF(x2, y2) << QPointF(x1, y3);
painter->setRenderHint(QPainter::Antialiasing);
painter->drawLines(points);

在此处输入图片说明

Now a new mock up is send to me and I have been asked to implement a focus icon which can be seen in top left corner. 现在,将向我发送一个新的模型,并要求我实现一个焦点图标,该图标可以在左上角看到。

Two requests are a bit different for example focus icon is filled with white color. 两个请求有些不同,例如焦点图标用白色填充。

Now I am thinking creating a square and fill it with white than draw two lines in the middle of it. 现在,我正在考虑创建一个正方形并用白色填充它,而不是在其中间画两条线。 Is it a good way to go? 这是一个好方法吗? Did anyone done something like this before and has samples? 有人做过这样的事情并且有样品吗?

If anyone need something like that the code below created a similar shape to the one at the top left of the picture in the question 如果有人需要这样的代码,下面的代码将创建与问题图片左上角相似的形状

QRectF newRec = rect;
painter->save();
newRec.setSize( newRec.size() / 20 * 11 );
painter->setBrush(Qt::white);

QColor colorRect( LMCTheme::Instance()->GetColor(InternalStuff::ColorIconInfoBarArrow));
painter->setPen(QPen( colorRect, 3, Qt::SolidLine, Qt::RoundCap));
painter->translate( rect.width()/2, rect.height()/10 );
painter->rotate(45);
painter->setRenderHint(QPainter::Antialiasing);

painter->drawRect(newRec);
painter->restore();

QColor color(LMCTheme::Instance()->GetColor(InternalStuff::ColorIconInfoBarBackground));
painter->setRenderHint(QPainter::Antialiasing);
painter->setCompositionMode(QPainter::CompositionMode_Clear);
painter->setPen(QPen(color, 3, Qt::SolidLine, Qt::RoundCap));
painter->drawLine( QLine(QPoint(rect.width()/2, rect.height()/10 ), QPoint(rect.width()/2, rect.height() - rect.height()/10 ) ) );
painter->drawLine( QLine(QPoint(rect.width()/10, rect.height()/2), QPoint(rect.width()*9/10, rect.height()/2)) );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM