Issue with moving QGraphicsItem Fast
I do have a QGraphicsScene rendered in a QGraphicsView.
I connected an horizontal slider position with the position of a QGraphicsItem, both added to the scene.
The slider was added by using a QGraphicsProxyWidget.
WHen I move the slider from left to right, the QGraphicsItem does the same.
However, when moving the slider fast, from left to right, everything is smooth and perfect, from right to left the QGraphicsItem disappears sometimes while moving.
Do you know why?
I just connected this way
//convert newposx to pixel value
"disappear" as in "never seen again", or are you talking about a flickering effect?
Flickering effect indeed !
Are the slider and item very close to each other? If so, try out if the effect is still there if you put a bit of distance between then.
What do you actually do in the item's slot?
Since I don't know such flickering effects (at least on typical PC hardware), I suspect the slider being used via proxy item. Can you test what happens when the events are generated some other way, e.g. by a timer, not by the slider?
Thanks for your help :)
The slider and the item are indeed touching each other as I want the QGraphicsItem ( a custom line) to make the continuation of the slider's handle.
I will try what you are proposing, however, its weird that this only appears from right to left and not from left to right doesnt it?
bq. What do you actually do in the item's slot?
I dont have item's slot, I just have a slot for my mainwindow which will move this item in the scene by using setPos() according to the slider's signal.
If all you do is calling setPos(), you shouldn't get this effect.
What type does your QGraphicsItem have? If it's custom, are you sure the boundingRect is calculated correctly?
Yes it is just what I do... I subclassed QGraphicsItem and added a drawLine in the paint method.
My bounding rect is calculated correctly too .. It is not updated when the item moves but I think it should not, as its a local bouding rect.
I cant have a look at the code right now (I am at work) but I am pretty sure its what I did.
But cant it come from the intersection of the item (line) with the slider as you mentionned before?
what means "convert newposx to pixel value"? how do you do that?
I used :
int QStyle::sliderPositionFromValue ( int min, int max, int logicalValue, int span, bool upsideDown = false )
to have a pixel value from the slider value as I want the line and the slider's header to align.
Asperamanca : after some tests, it looks like its because of the bounding rect you were right ;)
However, I dont know how to set it properly. I was thinking that the bounding rect doesnt need to update if you change the position.
I have on my line :
@void Item::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
QBrush brush(Qt::blue); painter->drawLine(0,0,0,500);
QRectF Item::boundingRect() const
and in my window the slot:
@void MainWindow::changeXLinePos(int val)
int val2 = slid->style()->sliderPositionFromValue(0,1000,val,slid->width());
qDebug() << "val" << val;
qDebug() << "pix" << val2;
How should I set the bounding rect correctly while the item s moving?
Should I tale the new position as an attribute of the item, update the bounding rect after calling prepareGeometryChange?
Thanks for your help !
no idea? ;)