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. QGraphicsView and items, I don’t know how to describe the problem correctly, so I couldn’t find the answer
Forum Updated to NodeBB v4.3 + New Features

QGraphicsView and items, I don’t know how to describe the problem correctly, so I couldn’t find the answer

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 145 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.
  • D Offline
    D Offline
    Daniil S.
    wrote on last edited by Daniil S.
    #1

    hi all, i have a problem
    i have a background item on scene, and cursor item whose parent is background item, QGraphicsView resizeEvent calls setTransform of the background item

    QTransform matrix(background_item_->transform());
      matrix.scale(this->transform().m11() / scale_facor_x_, this->transform().m22() / scale_factor_y_);
      QRectF view_rect(mapToScene(this->viewport()->rect()).boundingRect());
    
      scale_facor_x_ = (view_rect.width() / background_item_->boundingRect().width();
      scale_factor_y_ = (view_rect.height() / background_item_->boundingRect().height();
    
      matrix.scale(scale_facor_x_, scale_factor_y_);
    
      background_item_->setTransform(matrix);
      background_item_->setPos(QPointF(0, 0));
    

    after this cursor position updates, but cursor has flag ItemIgnoresTransformations and fixed width 20

    cursor_item_->setRect(QRectF(QPointF(0, 0), QSizeF(20, this->sceneRect().height())));
    cursor_item_->setPos(cursor_item_->pos().x(), background_item_->mapFromScene(QPointF(0, 0)).y());
    

    in mousePressEvent I need to check if the cursor is catching, but the cursor rect is wider than the visible rect, so the cursor is grabbed in a larger area like in the screenshot

    f71650d7-53ff-4d57-b636-1ab430df5916-image.png

    QRectF CursorItem::boundingRect() const
    {
      return QRectF(this->rect().x() - this->rect().width() / 2, this->rect().y(), this->rect().width(), this->rect().height());
    }
    
    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