Update scene
-
hi
put qDebug() << "in shot:"
in the
MainWindow::Shot()
to make sure its actually called mutiple times. -
if pos() returns 0,0 , it must mean the items is actually at 0,0.
-
@mrjj and the other ones return 0,0. The object are unique they are all parents and have no child, I want to get the positions of each object so I could move them
-
@mrjj and the other ones return 0,0. The object are unique they are all parents and have no child, I want to get the positions of each object so I could move them
@mandruk1331
Something is not right.
Unless they are all really drawn at 0,0 then pos() should return the
actual position.
Did you new a QGraphicsRectItem and inserted directly in the list? -
@mandruk1331
Something is not right.
Unless they are all really drawn at 0,0 then pos() should return the
actual position.
Did you new a QGraphicsRectItem and inserted directly in the list?@mrjj yes, and in the constructor I have set theirs poistions
-
@mrjj yes, and in the constructor I have set theirs poistions
Ok, then they should still have the pos, unless you swapped with a
item having 0,0. -
Can I ask how any values (rects) you try to visualize?
-
@mrjj 10
-
@mrjj 10
@mandruk1331
ok.
And did you write the sort also? -
@mandruk1331
ok.
And did you write the sort also?@mrjj yes
for( int i=0;i<random_numbers_.size()-1;i++){
for(int j=0;j<random_numbers_.size()-1;j++){if(random_numbers_[j]>random_numbers_[j+1]){ count++;
QTimer::singleShot(1000*count, [=]{ MainWindow::Shot(j);});
} } }
-
ok.
Don't really look like bubble sort.
:) -
Hi
I made a half assed bubble sort visualization using
widget painting.2 things wrong with it.
The actual sort should rather be able to single step but instead
I use a delay function to slow down drawing. (not pretty)
So consider it concept rather than good practice.That said, its meant for inspiration for your project.
-
Hi
I made a half assed bubble sort visualization using
widget painting.2 things wrong with it.
The actual sort should rather be able to single step but instead
I use a delay function to slow down drawing. (not pretty)
So consider it concept rather than good practice.That said, its meant for inspiration for your project.
@mrjj Thanks a lot,really:-)
-
I know I'm late to the party, but for what it's worth:
- There is rarely ever a need to manually update the GraphicsScene. It will automatically update parts whenever you move items (setPos), or change properties of ready-to-use items such as QGraphicsRectItem
- If you implement your own item and your own paint method, naturally the scene cannot know which properties will affect the paint and which won't. Therefore, you just call update() on the item after you changed any properties that affect the way the item looks
- If you change the boundingRect(), don't forget to call prepareGeometryChange(), otherwise you will have nasty painting effects
- Re sorting: qSort, anyone?