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. Can I use QPainterPath shape() const instead QRectF boundingRect() const for Item movility?

Can I use QPainterPath shape() const instead QRectF boundingRect() const for Item movility?

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.8k 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.
  • R Offline
    R Offline
    Rhadel
    wrote on last edited by
    #1

    I have a custom QGraphicsItem class. I can click on and drag on the scene:

    @
    this->setFlag(QGraphicsItem::ItemIsMovable);
    @

    Now, I would like to know if I can replace the boundingRect() method, used to check if I'm clicking on the item, for shape(), where I ve a more specific region to check this click. How can I do that?

    Thank you.

    ------------------- EDITED-----------------------

    Thank you for your fast reply.

    I added in custom QGraphicItem class the following line in costructor:

    @
    this->setFlag(QGraphicsItem::ItemClipsToShape, true);
    @

    And I've checked if mouse pressent event is called after clicking on my shape:
    @
    mousePressEvent(QGraphicsSceneMouseEvent *event)
    @

    My shape is build with the addition of some QRectF:

    @
    QPainterPath result;
    foreach (blah blah){
    //Building QRectF here
    result.addRect(currentRect);
    }
    @

    But mouse event is only called when clicking on the first added rectangle. I know there are more than 1 rectangle, because I have drawn the QPainterPath, and I can see all the rectangles that I added.

    Maybe some help with that?

    Thank you!

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andruxa
      wrote on last edited by
      #2

      Check QGraphicsItem::ItemClipsToShape setting... It seems to be what you need:

      bq. The item clips to its own shape. The item cannot draw or receive mouse, tablet, drag and drop or hover events outside its shape. It is disabled by default. This behavior is enforced by QGraphicsView::drawItems() or QGraphicsScene::drawItems(). This flag was introduced in Qt 4.3.

      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