PDA

View Full Version : Very Strange problem



dreamer
29th April 2008, 23:15
It is a whole day, that i try to resolve this problem.

In a few words:

I have myscene class (custom QGraphicsScene), myview class(custom QGraphicsView) and myrect(custom QgraphicsRectItem).........

I insert myrect into myscene and i can move and select it without any problem.
Now i'm trying to implement the resize behaviour of myrect.

so, i introduce in my implementation a variabile of type enum that set the modality of my scene(enum type{MoveItem,Resizing};)...for example.....
i also have a variable(enum type_resize) in myrect class, that set the kind of resize(NO_RESIZE, horizzontal, vertical, .......)

my example code:

myscene.class


mousePressEvent(QGraphicsSceneMouseEvent * mouseEvent){

((rectItem*)(mouseEvent->widget()))->set_resize_type(rectItem::vertical);
setMode(Resizing);

QGraphicsScene::mousePressEvent(mouseEvent);
}

mouseMoveEvent( QGraphicsSceneMouseEvent *event ) {
QGraphicsScene::mouseMoveEvent(event);
}


myrect.class


mousePressEvent(QGraphicsSceneMouseEvent * mouseEvent){
if(myscene::Resizing)
QGraphicsRectItem::mousePressEvent(mouseEvent);
}
mouseMoveEvent(QGraphicsSceneMouseEvent *event){
if(myscene::Resizing)
//execute the right resizing, depending on the value of type_resize
?????????????????????????????????????????
Here the problem.....Why the variable type_resize(enum) has always the value of 0(the first value of the enum-->NO_RESIZE???)???????
A wrote some printf for debugging, and i saw that 1 step before the type_resize has the "right" value, but when i print it in the mouseMoveEvent of myrect it change it's value.......Who change this value??Perhaps some spirit.....
}

dreamer
30th April 2008, 09:20
I note that the type_resize variable, has the value that i give it in the constructor......

so if i give it the value of '0', i can modify it with the public function set_type_resize(), but then it return to '0'

The same behaviour appears with other int value.......

SO, IT HAS THE SAME VALUE I GIVE IT IN THE CONSTRUCTOR

In myrect class, i implement two type of constructor:


rectItem(QMenu *menu, const QRectF & rect, QGraphicsItem * parent):QGraphicsRectItem(rect,parent){}

and


rectItem(QMenu *menu, QGraphicsItem * parent):QGraphicsRectItem(parent){}


In these constructors i set my private int variable.......
So, What's the matter? Perhaps some function recall the constructor for repaint the item on the scene??? ?????????