Re: QBrush pattern problem
Indeed, it behaves strange. Especially when you resize the widget. It might be a result of some round-off errors, but IMO you should show this example to the Trolls.
Below is a working example:
Code:
#include <QApplication>
#include <QPainter>
#include <QWidget>
{
protected:
{
painter.setPen(Qt::red);
QBrush brush
(Qt
:: Dense6Pattern);
brush.setColor(Qt::blue);
painter.setBrush(brush);
painter.setWindow(0, 0, 1000, 1000); // try to comment out this line
painter.drawRect(50, 50, 100, 200);
painter.setWindow(0, 0, 2000, 2000);
painter.drawRect(500, 100, 200, 400);
painter.setWindow(0, 0, 3000, 3000);
painter.drawRect(1350, 150, 300, 600);
painter.setWindow(0, 0, 4000, 4000);
painter.drawRect(2600, 200, 400, 800);
painter.setWindow(0, 0, 5000, 5000);
painter.drawRect(4250, 250, 500, 1000);
}
};
int main( int argc, char **argv )
{
Test t;
t.show();
return app.exec();
}
Re: QBrush pattern problem
6 years later... I ran into this same problem, and only found this post referring to it. I solved it by doing the following:
Code:
painter.setWindow(0,0,_logicalWidth,_logicalHeight); //setting the logical window
QBrush brush
(Qt
::blue,Qt
::Dense6Pattern);
//add a transform to the brush to undo the logical scaling
brush.setTransform( QTransform::fromScale( width()/_logicalWidth, height()/_logicalHeight) );
painter.setBrush(brush);
//and carry on drawing
Hopefully this helps anyone who stumbles across it!