4

i want to set a QPixmap as brush for a rectangle in paint method .I do this work but it doesn't set accurately .I test many value for width and height but yet it wasn't good .Overall, what sizes should I set for the rectangle surrounding the photo that put in it properly?

void set_coin::paint(QPainter *painter, const QStyleOptionGraphicsItem  *option,)
{
QRectF rec(x_size,y_size,10,30);
QPixmap coin(":pictures/image/coin.jpg");
coin=coin.scaled(10,30);
painter->setBrush(QBrush(coin));
painter->setPen(Qt::NoPen);
//painter->drawRect(rec);
painter->drawRoundedRect(rec,10,10);
}
QRectF set_coin::boundingRect() const
{
  return QRectF(x_size-10,y_size-10,20,40);
}

i want it What is shown in program(i put 4 coin in my scene)

maryam
  • 1,437
  • 2
  • 18
  • 40
  • 2
    Can you edit your post by adding an image of what you get and an other of what you want please ? – Martin Jul 05 '14 at 16:52
  • i want to have that complete coin.in another image i put 4 coin in my scene but are shown incompletely. – maryam Jul 05 '14 at 17:44

1 Answers1

2

The problem is here:

QRectF rec(x_size,y_size,10,30);

The doc says:

QRectF::QRectF ( qreal x, qreal y, qreal width, qreal height )

The last two arguments are x_size and y_size, not the first two one ;)

EDIT: (Because I didn't really understand the problem first)

I tried your code and in fact, your image is not "accuracy" because you see 4 pieces of mage on your small 10 to 30 area.

The solution is to set x_size (respectively y_size) a value which is a multiple of 10 (respectively 30).

If you try x_size = 100 and y_size = 300, it will works ;)

Martin
  • 877
  • 8
  • 20
  • i know this.`greal width` =10 `greal height`=30.these are my rectangle 's dimensions. – maryam Jul 05 '14 at 19:09
  • I'm sorry to disturb you again.i test with 100,300.it was good.but in my application i have some bricks that i want to put these coins on their.it means `x_size` and `y_size` is changeable.i deal with problem before for another images.is there a way that solve it? is related This problem to the dimensions of the original photo?(144x152 pixels) – maryam Jul 06 '14 at 05:17