Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Rotate QBrush Texture Pattern
Forum Updated to NodeBB v4.3 + New Features

Rotate QBrush Texture Pattern

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 430 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mmagic
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • Chris KawaC Online
      Chris KawaC Online
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by Chris Kawa
      #2

      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.save();
      
      p.translate(rect_x, rect_y);
      p.rotate(angle);
      
      QRect r(0, 0, rect_width, rect_height);
      p.fillRect(r, b);
      
      p.restore();
      

      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.

      1 Reply Last reply
      2

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved