Important: Please read the Qt Code of Conduct -

Rotate QBrush Texture Pattern

  • Hello,
    I am drawing square, and each square has its given angle.
    I use QPixmap as the Brush texture Pattern.
    How to rotate the QPixmap of the QBrush in function of the square angle?
    Thank you

  • Moderators

    You can match the rotation of the rectangle and the brush with its setTransform() method, but it might be easier to just set the painter transform and let it transform the rectangle and the brush in one go. Something like:

    QPainter p(whatever);
    QBrush b(QPixmap("something.png"));;
    p.translate(rect_x, rect_y);
    QRect r(0, 0, rect_width, rect_height);
    p.fillRect(r, b);

    The save()/restore() calls are there to preserve the original transform and are only needed if you want to use that painter for something else too.

Log in to reply