Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QGraphicsPixmapItem catch mouse over Corner
Forum Updated to NodeBB v4.3 + New Features

QGraphicsPixmapItem catch mouse over Corner

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 123 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SeppyQT
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved