[Interest] Draw ellipse (and etc.) the same way as cosmetic QPen

Ian Thomson Ian.Thomson at iongeo.com
Tue Jan 14 13:38:52 CET 2014


Have you tried adding child GraphicsItems for each of the dots and
setting the flag QGraphicsItem::ItemIgnoresTransformations? That should
do the trick.

Ian.


On 14/01/14 12:11, Dmitrii Volosnykh wrote:
> Is there a possibility to draw something irrespectively to scene
> transformations such as cosmetic QPen?
>
> I've tried to approaches but none brings me to a success. I have some
> scene that may contain a polyline with vertices represented by bold
> dots. While polyline and thus coordinates of dots should respect scene
> scaling, I don't want the size of dots to change.
>
> Here's the Polyline's imlementation of paint() method (Polyline inherits
> QGraphicsPolygonItem):
>
> void PolylineItem::paint(QPainter* const painter, const
> QStyleOptionGraphicsItem* const option, QWidget* const widget)
> {
>      Q_UNUSED(option);
>      Q_UNUSED(widget);
>
>      painter->setPen(pen());
>      painter->setBrush(brush());
>
>      painter->drawPolyline(polygon());
>
> #if 0
>      if (polygon().size() > m_points.size()) {
>          for (int i = m_points.size(); i < polygon().size(); ++i) {
>              auto* const point = new QGraphicsEllipseItem(this);
>              point->setPen(pen());
>              point->setBrush(brush());
> //            point->setFlag(QGraphicsItem::ItemIgnoresTransformations);
>              m_points.append(point);
>          }
>      } else if (polygon().size() < m_points.size()) {
>          const int count = m_points.size() - polygon().size();
>          for (int i = 0; i < count; ++i) {
>              delete m_points.takeLast();
>          }
>      }
>
>      const qreal r = pen().widthF() * POINT_RADIUS_RATIO;
>      for (int i = 0; i < m_points.size(); ++i) {
>          const QPointF& c = polygon().at(i);
>          m_points[i]->setRect(c.x() - r, c.y() - r, 2 * r, 2 * r);
>      }
> #else
>      const qreal r = pen().widthF() * POINT_RADIUS_RATIO;
>      foreach (const QPointF& point, polygon()) {
>          painter->drawEllipse(point, r, r);
>      }
> #endif
> }
>
> The code between #else and #endif directives is the first
> straightforward way I've tried. The points are scaled in size.
> The part between #if and #else behaves the same when point->setFlag() is
> commented out. If I enable this invokation, the points are constantly of
> the same size, as I want it, but their positions are scaled outside the
> polyline. In fact, they are not scaled, but the whole scene with the
> polyline itself are scaled, so it looks like the dots are moving outside.
>
> Can't figure out what to do. Asking for help.
>
> Regards,
> Dmitrii.
>
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>


________________________________


This email and any files transmitted with it are confidential and are intended solely for the use of the individual or entity to whom they are addressed. If you are not the original recipient or the person responsible for delivering the email to the intended recipient, be advised that you have received this email in error, and that any use, dissemination, forwarding, printing, or copying of this email is strictly prohibited. If you received this email in error, please immediately notify the sender and delete the original.




More information about the Interest mailing list