I have to click on the edge of the item, and it has to be on the pixel. Very hard to click it with the mouse.
I have to click on the edge of the item, and it has to be on the pixel. Very hard to click it with the mouse.
Apparently the inside of the item is empty. If simply setting a brush doesn't help you'll have to reimplement the shape() of the item.
meazza (31st March 2011)
I fixed it i think. I thought since i add the items during a pressEvent and when i tried to move the item i press the mouse so the pressEvent funktion was called hence not allowing me to move it. So added QGraphicsScene::mousePressEvent(mouseEvent); if iwas not adding items in the pressEvent.
Well it works now but do you find this a reasonable solution?
I don't think adding items in a mouse press event is a reasonable solution. I tend to lean towards more high-level solutions.
Well I am not a master of zen yet, but hopefully someday I will be. What would that high-level solution be? Just asking out of curiosity, not gonna try it out this time. Not high-level yet
.
Thanks for all your help
Like emitting a signal "hey, I want item to be added at these coordinates" and then handling it in a dedicated method that can be called from different contexts. And mousePress is probably a bad place to do it anyway, mouseRelease would be a better one.
What about the solution of reimplement the function mouseMoveEvent()?
You can do something like that too:
Qt Code:
PolygonItem->move(event->x(),event->y()); }To copy to clipboard, switch view to plain text mode
I have found another question. How do QWidgets behave in the graphicsscene? Do I need to use the QGraphicsProxyWidget to be able to move it or? Because i cant set flags to a normal QWidget.
Qt Code:
Embedded *MyWidget = new Embedded(); QGraphicsProxyWidget *proxy = new QGraphicsProxyWidget(); proxy = addWidget(MyWidget); proxy->setPos(mouseEvent->scenePos()); addItem(proxy); figur = 0;To copy to clipboard, switch view to plain text mode
I tried this and it positions as i would like to but cant move it..Maybe I am waaaay out there on this one![]()
I'd say you can't move it because the widget handles the event so it never reaches the scene code responsible for moving the item.
Bookmarks