Qt World Summit: Register Today!

QPainter and drawing stroke inside/outside/middle of the path

  • Hello all,
    How can I draw inner/outer/center stroke in QPainter?

  • @seyed

    Had you try to refer to the Qt Documentationof QPainter?


  • @Charlie_Hdz, yes but not helped me.

  • @seyed

    To be concrete, QPainter won't solve your problems, I know, it's kind of counterintuitive, but what really is important is to handle the QPaintEvent and use specific object to draw (QBrush, QRect,... and so on). Indeed, QPainter is the handler of everything that you will paint. If you don't have tools you won't paint anything.

    Take it in this way... QPainter is a real Painter, and what can a Painter do without tools and place to paint?

    Please show me some advance and I will teach you what you need.


  • @Charlie_Hdz
    OK, thank you for explanation. What is my scenario? A: I want to create a custom QtQuick Item (QQuickPaintedItem) which will draw a path. I named it PathDrawer.
    There is paint method of my item:

    void PathDrawer::paint(QPainter *painter)
        QPen pen(m_strokeColor, m_lineWidth);
        QBrush backBrush(m_fillColor);
        if(!m_points.isEmpty()) {
            painter->drawPolygon(QPolygonF(m_points), m_fillRule);

    But my problem is that line will draw out of the region and I what make it controllable.

  • Question,

    Does it painting already?


Log in to reply