[Qt-jambi-interest] maping & Cooirdinates
Dawid Sip
vad at poczta.onet.pl
Wed Aug 6 20:01:23 CEST 2008
Hi,
Im having a tough time with Rectangle positioning in a scene.
Basicaly I'm using a custom Cursor made from an rectangular image. I
take the im and get its .rect(), I than make
graphicsView.mapToScene('the rectangle'), and get a polygon from which i
create graphicsItem which i add to the scene. I want this item to be
added at the cursor position which i have in QPoint p, do i do
polygonItem.moveBy(p.x(), p.y()). Unfortunately this does not place the
item where the cursor is. This has something to do with the
graphicsView.mapToScene transformation. When I ommit this transformation
and create polyItem directrly from the 'rect' and move it by the amount
in p, all works fine. I cant leave it like this though because i need
the mapToScene to make the polyItem dimensions appear exactly like the
cursors. What do i do wrong here?
protected void markForegroundRegion(QPoint p){
//p is in scene coords
// QPolygonF pol = this.view.mapToScene(cursorIm.rect());
QPolygonF pol = new QPolygonF(new QRectF(cursorIm.rect()));
QRectF rec = pol.boundingRect();
QGraphicsPolygonItem poIt = new QGraphicsPolygonItem(pol);
poIt.setPos(-rec.width()/2, -rec.height()/2);
poIt.moveBy(p.x(), p.y());
poIt.setBrush(new QBrush(new QColor(228, 18, 28, 228)));
poIt.setZValue(46);
this.scene.addItem(poIt);
}
Dave
More information about the Qt-jambi-interest
mailing list