QGraphicsPixmapItem catch mouse over Corner
Unsolved
General and Desktop
-
Dear Community,
I accomplished to catch a OnMouseOver event for my QGraphicsPixmapItem via inheritance of QGraphicsView
class CGraphicsView : public QGraphicsView { Q_OBJECT private: std::atomic<bool> stop_move = false; public: CGraphicsView(QGraphicsScene* scene, QWidget* parent = nullptr) : QGraphicsView(scene, parent) {} CGraphicsView(QWidget* parent = nullptr) : QGraphicsView(parent){} virtual void mouseMoveEvent(QMouseEvent* event) override; void startStopMove(bool stop = false); signals: Q_SIGNAL void GraphicsViewMouseMove(void* sender, QMouseEvent* args); }; /// #include "CGraphicsView.hpp" void CGraphicsView::mouseMoveEvent(QMouseEvent* event) { emit this->GraphicsViewMouseMove(reinterpret_cast<void*>(this), event); if(!this->stop_move) QGraphicsView::mouseMoveEvent(event); } void CGraphicsView::startStopMove(bool stop) { this->stop_move = stop; }
Now I can put a OpenHandCursor to symbolize that you can grab and move the picture.
But now I want to make another Cursor if the user is around the corners of the item
uint64_t counter = 0; void mouseOver(void* sender, QMouseEvent* event) { auto rect = this->boundingRect(); auto cursor = this->cursor(); if (rect.contains(event->pos())) { auto pos = this->getPosition(); qDebug((std::to_string(counter)+ " -> " + std::to_string(pos.first)).c_str()); if (rogue::approximate(pos.first,10.0,10.0) && rogue::approximate(pos.second, 10.0,10.0)) { cursor.setShape(Qt::CursorShape::CrossCursor); } else cursor.setShape(Qt::CursorShape::OpenHandCursor); } this->setCursor(cursor); ++counter; }
ignore counter variable it is just a global debug Variable which will be removed
rogue::approximate is just a template function which actually returns a bool if x > firstlimit and if x < secondlimit
so it emulates if( llimit < val < rlimit)template<class TYPE> bool approximate(TYPE val, TYPE llimit, TYPE rlimit) { if (val > llimit) { if (val < rlimit) return true; } return false; }
I am used to use template<class X> and I continued it even typename X is legal too.
How do I catch MouseOverCorners?
Thanks for replies.