Vote count:
0
Helo.
I have cerian problem with class QGrpahiscObject. I want to draw rectangles with cordinates. Cordinates is for example.
919 28 758 234
938 27 1093 237
1403 258 1532 357
1936 492 1838 571
2950 246 3115 351
1142 1005 1304 1170
1387 769 1146 970
This cordinates is generecic for my other program. In this Program I draw rectangles, and Save to file this cordinates, Then I open next program (the one with which I have probelm), and I try draw this same rectangles but using QGraphicsView/Scene/Item. Below is constructor where I createt rectangle to display on certian pixmap. This class inhered by QGraphicsObject
Field::Field(QString name, int xa, int ya, int xb, int yb) : name(name) , xa(xa) , ya(ya) , xb(xb) , yb(yb) , Object(name)
{
fieldRect.setCoords(xa , ya , xb , yb);
brush = new QBrush(Qt::gray);
ef = new QGraphicsOpacityEffect(this);
ef->setOpacity(0.62);
this->setGraphicsEffect(ef);
qd "info " << fieldRect.height() << fieldRect.width() << fieldRect.size() << fieldRect.topLeft() << Cordinate();
}
So, here is overload virtual function
bounding
QRectF Field::boundingRect() const
{
return QRect(xa , ya , xb , yb);
}
drawing
void Field::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
painter->setBrush(*brush); // brush is external object in class Field
painter->drawRect(fieldRect);
}
and
advance
void Field::advance(int phase)
{
setPos(mapToParent(0 , 0));
update();
}
Ofcors first I create QGraphicsView next creates object QGraphicsScene finally a create object Field. This is all worked but please tell my why not all rectangle is drawing. I want to get 7 rectangles, but I giv only 4. Does this have something to do with negative size ? This is qDebug info size to this rectangles.
wczytane kordynaty 919 28 758 234
info 207 -160 QSize(-160, 207) QPoint(919,28) "919 28 758 234"
wczytane kordynaty 938 27 1093 237
info 211 156 QSize(156, 211) QPoint(938,27) "938 27 1093 237"
wczytane kordynaty 1403 258 1532 357
info 100 130 QSize(130, 100) QPoint(1403,258) "1403 258 1532 357"
wczytane kordynaty 1936 492 1838 571
info 80 -97 QSize(-97, 80) QPoint(1936,492) "1936 492 1838 571"
wczytane kordynaty 2950 246 3115 351
info 106 166 QSize(166, 106) QPoint(2950,246) "2950 246 3115 351"
wczytane kordynaty 1142 1005 1304 1170
info 166 163 QSize(163, 166) QPoint(1142,1005) "1142 1005 1304 1170"
wczytane kordynaty 1387 769 1146 970
info 202 -240 QSize(-240, 202) QPoint(1387,769) "1387 769 1146 970"
Hopefully that you understand me...
Qt boundingRect() not draw bound
Aucun commentaire:
Enregistrer un commentaire