[SOLVED]QGraphicsView's dragMode
-
Hello,
I have a small problem. After creating the class which is inherited from QGraphicsView and reimplementing mouse events I got a small problem: I can't move items. Yes, the flag QGraphicsItem::ItemIsMovable is set. I guess I need to implement my own mechanism for that. But before it I want to ask you, guys: Is in this situation another way for getting both mouse events and saving dragMode functionality which is provided by default?
-
Is in this situation another way for getting both mouse events and saving dragMode functionality which is provided by default?
yes, you need in all mouse events give event further to QGraphicsView.
@
void YoueView::mousePressEvent(QMouseEvent *event)
{
//your code
//and in the end just do this
QGraphicsView::mousePressEvent(event);
}
@
and do this for mouse move and release event. -
Thank you! It works!
I didn't consider that at all. -
[quote author="dmitrij" date="1320052884"]Thank you! It works!
I didn't consider that at all.[/quote]
You are welcome :)
Please mark the post as [Solved], thank's. -
[quote author="dmitrij" date="1320052884"]Thank you! It works!
I didn't consider that at all.[/quote]As general rule of thumb:
If you want to add functionality in a virtual method you reimplement, make sure to call the base class' implementation too. Whether before or after your code depends, of course. And make sure you call the direct base class' implementation (not one of that's parents), even if that class doesn't actually reimplement the method - it might do so in the future and you're on the safe side in that case. -
[quote author="Volker" date="1320062134"]
As general rule of thumb:
If you want to add functionality in a virtual method you reimplement, make sure to call the base class' implementation too. Whether before or after your code depends, of course. And make sure you call the direct base class' implementation (not one of that's parents), even if that class doesn't actually reimplement the method - it might do so in the future and you're on the safe side in that case.[/quote]Thank you! Now I have full understanding about what's going on in QT's framework.