Important: Please read the Qt Code of Conduct -

QGraphicsPixmapItem catch mouse over Corner

  • Dear Community,

    I accomplished to catch a OnMouseOver event for my QGraphicsPixmapItem via inheritance of QGraphicsView

    class CGraphicsView : public QGraphicsView
    	std::atomic<bool> stop_move = false;
    	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);
    	Q_SIGNAL void GraphicsViewMouseMove(void* sender, QMouseEvent* args);
    #include "CGraphicsView.hpp"
    void CGraphicsView::mouseMoveEvent(QMouseEvent* event)
    	emit this->GraphicsViewMouseMove(reinterpret_cast<void*>(this), 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)) {

    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.

Log in to reply