Hello,
I'd like to fill a QGraphicsItem with a pattern specified by a bitmap. Just like Qt::SolidPattern, Qt::Dense1Pattern, but a custom defined one.
For now I've tried drawing a QBitmap for the pattern with only black and white, and appliy this to a QBrush with a color. But the pattern doesnt draw correctly on the screen, and also I get this error:
QBrush: Incorrect use of TexturePattern
On MacOS the items are not filled, and in Windows and Linux the filling is not correct and it breaks when zooming, for example.
The code I used to create the brush is the following:
QBitmap *texture
= createBrushFromPacket
(layerPacket
);
QBrush fillBrush
(fillColor, Qt
::TexturePattern);
fillBrush.setTexture(*texture);
fillBrush.setColor(fillColor);
QBitmap *texture = createBrushFromPacket(layerPacket);
QColor fillColor = QColor::fromRgb(r, g, b);
QBrush fillBrush(fillColor, Qt::TexturePattern);
fillBrush.setTexture(*texture);
fillBrush.setColor(fillColor);
To copy to clipboard, switch view to plain text mode
createBrushFromPacket returns the bitmap, and r, g, b contain the RGB color values.
Later on my code, when I draw the QGraphicsItem I do the following:
item->setBrush(fillBrush);
item->setPen(fillColor);
QGraphicsEllipseItem *item = new QGraphicsEllipseItem(rx, ry, radius, radius);
item->setBrush(fillBrush);
item->setPen(fillColor);
To copy to clipboard, switch view to plain text mode
What am I doing wrong?
Thanks in advance,
Francesc Vila
Bookmarks