Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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



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



  • @seyed

    Had you try to refer to the Qt Documentationof QPainter?

    http://doc.qt.io/qt-4.8/qpainter.html



  • @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.

    Thanks



  • @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)
    {
        painter->setRenderHint(QPainter::Antialiasing);
    
        QPen pen(m_strokeColor, m_lineWidth);
        QBrush backBrush(m_fillColor);
        pen.setCapStyle(Qt::RoundCap);
        painter->setBrush(backBrush);
        painter->setPen(pen);
    
        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?

    Thanks


Log in to reply