Results 1 to 2 of 2

Thread: QGraphicsRectItem subclass and mouseMoveEvent

  1. #1
    Join Date
    May 2012
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default QGraphicsRectItem subclass and mouseMoveEvent

    Hi!

    I have a subclass of QGraphicsRectItem. The mouseMoveEvent handler looks like this:
    Qt Code:
    1. void BTNodeGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent* event)
    2. {
    3. QGraphicsRectItem::mouseMoveEvent(event);
    4. qDebug() << rect().x() << " " << rect().y();
    5. }
    To copy to clipboard, switch view to plain text mode 

    The item drags like I expect. But the qDebug statement outputs the same coordinates as I drag it. Shouldn't the rect be changing as it is dragged?

  2. #2
    Join Date
    May 2012
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsRectItem subclass and mouseMoveEvent

    OK, thanks again for looking! Here's what it turned out to be after quite a bit of messing around:

    Qt Code:
    1. QPointF newCenter(mapToScene(rect().center().x(), rect().center().y()));
    2. qDebug() << newCenter.x() << " " << newCenter.y();
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QGraphicsRectItem vs QGraphicsPolygonItem
    By Doru in forum Qt Programming
    Replies: 0
    Last Post: 26th January 2011, 07:12
  2. Replies: 8
    Last Post: 12th February 2010, 02:41
  3. Take a screenshot of a QGraphicsRectItem
    By yazwas in forum Qt Programming
    Replies: 1
    Last Post: 12th October 2009, 13:14
  4. QGraphicsRectItem
    By c_srikanth1984 in forum Qt Programming
    Replies: 1
    Last Post: 29th July 2009, 09:04
  5. How can I use QGraphicsRectItem?
    By learning_qt in forum Qt Programming
    Replies: 3
    Last Post: 14th January 2009, 10:00

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.