Why do you claim item->pos().x() returning 0 is an incorrect result? What does it have to do with item->data()?
Why do you claim item->pos().x() returning 0 is an incorrect result? What does it have to do with item->data()?
Here's what happening on screen: there are musical notes selected by the rubberband. The routine takes the selectedItems, and item->pos().x() is supposed to return the x coordinate of each note. The other data routines provide additional info needed for other purposes. The data is coming through for the various notes, so the itemlist is being iterated properly but the x coordinate is not being returned from item->pos().x().Each one returns 0. Now, item->pos().x() works in other circumstances but not here for some reason. The docs say it should work. What am I missing?
How do you represent each note? How is the boundingRect() defined for the class representing the note? What is the parent object of each note?
Each note is a standard QGraphpicEllipseItem. I have not subclassed it at this point so the bounding rect should be pure standard issue. I have not assigned a specific parent to each note.
So how do you create those items? What rectangles do you pass for the ellipses?
Note* myNote = new Note;
myNote->setRect(gridX-(w/2), (y-(h/2)), w, h); // w= width, h == height, gridX is a grid-altered x location, y is the location on the staff vertically.
Also, I stated something wrong earlier. I have a class called Note that is of QObject and QGraphicsEllipseItem. I create a new Note and set that rect using the above line. I hope this is more helpful.
Last edited by devdon; 19th September 2011 at 22:57.
I do not call setpos on the ellipses.
So position of all your items is (0,0) and the value returned in your code snippet is correct. I guess you are incorrectly assuming that pos of your item should be equal to the centre of the item's bounding rect (gridX, y). That is not the case. To get that, create your items with rects (-w/2, -h/2, w, h) and then call setPos(gridX, y).
Bookmarks