PDA

View Full Version : Is there any API to set QBrush instance as Cosmetic



navi1084
1st February 2010, 08:46
Hi,
I have created a application which contains different shapes of QGraphicsItem with resizable handles/thumbs (derived from QGraphicsItem). I want only shapes to be zoom in/out. For that reason i made shapes pen as cosmetic which restrict the thickness of the pen to be changed.
Even i want shape's thumbs to be fixed in size even though it is zoomed in/out(same like cosmetic pen), but transformation should be applied i.e thumbs should be placed respective co-ordinates as per the zoom factor.
Is there anyway to make QBrush as cosmetic i.e restricting the shape to be in same size.

Thanks

navi1084
1st February 2010, 16:59
is there any way??? Please....


Thanks

wysota
1st February 2010, 18:22
For custom items when you do your own painting you should be able to adjust the brush based on the item transformation manually (i.e. reverse the transformation made by the scene). An alternative is to set the item to ignore transformations and implement zooming manually (by changing the size of the item).

navi1084
2nd February 2010, 04:00
Thank you for the reply.

After your comment (reverse the transformation made by the scene) I am using following set of code in derived class of QGraphicsPolygonItem():

void Handle::paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget )
{
Q_UNUSED(widget);
m_Brush.setMatrix(painter->matrix().inverted());
painter->setBrush(m_Brush);
painter->setPen(m_Pen);
painter->drawPolygon(m_Palygon);

}

The instance of Handle is child of another shape which is used for resizing. Hence parent's matrix will be applied here too. I cant use "ItemIgnoresTransformations". By applying the inverse of painter matrix to QBrush my problem is not resolving.

Is this is the way you suggested?

navi1084
2nd February 2010, 05:42
I saw a post in Qt center(http://www.qtcentre.org/threads/13950-Not-Scaling-QBrush-style-fro-qgraphics-view-item) which tell about the bug in brush matrix. But i am using QT 4.4, still unable to resolve the fix.

navi1084
2nd February 2010, 08:09
I am using QT commercial edition 4.4. Whatever matrix i am applying for QBrush is ignored by the painter.. Is this is a bug??

Thanks

navi1084
3rd February 2010, 03:47
Can anyone tell whether this issue is a bug? or is there any way to resolve this?