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. Setting boundingRect() for a custom QGraphicsObject drawn using mouse
Forum Updated to NodeBB v4.3 + New Features

Setting boundingRect() for a custom QGraphicsObject drawn using mouse

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 358 Views 1 Watching
  • 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.
  • MarKSM Offline
    MarKSM Offline
    MarKS
    wrote on last edited by
    #1

    I want to draw a custom rectangle when dragged using a mouse events. Since i need additional features like resizing the rectangle, contextMenuEvents() and other stuff, i subclassed QGraphicsObject and overriden pure virtual functions. Moreover, i have a subclassed QGraphicsScene which handles mouse events.

    What do i want:

    To be able to draw custom rectangle when mouse events are triggered on QGraphicsScene. Like left mouse button->drag.
    Drawing it simply using QGraphicsRectItem works fine.

    Problem:

    How to set boundingRect() of my custom rectangle and paint() or update the rectangle as the mouse moves on the QGraphicsScene?

    Currently, i have an empty subclassed RectItem. Which looks like this:

    RectItem::RectItem(QObject* parent) :
        QGraphicsObject()
    {
    
    }
    
    QRectF RectItem::boundingRect() const
    {
          // how to set bounding rect when rectangle is drawn dynamically using mouse?
    }
    
    void RectItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
    {
         // how to update paint() and show a rectangle to the user?
    }
    

    How to implement both boundingRect() and paint()?

    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