【问题标题】:Can I resize QGraphicsItem without creating a class that inherits QGraphicsItem?我可以在不创建继承 QGraphicsItem 的类的情况下调整 QGraphicsItem 的大小吗?
【发布时间】:2014-08-18 18:47:57
【问题描述】:

我想问一个问题,是否可以在不创建继承 QGraphicsItem 的类的情况下调整 QGraphicsItem 的大小。例如,像这样:

void MyScene::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
   point = event->scenePos();
   if( ArrowCursor )
   {
      curItem = this->itemAt( point, view->transform() );
      if( curItem && !curItem->isSelected() )
      {
         curItem->update( 10,10, 100, 100 );
      }

   }
}

【问题讨论】:

  • 作为更新的文档状态:“计划重绘此项目中 rect 覆盖的区域。您可以在需要重绘项目时调用此函数,例如它改变外观或大小。”所以它肯定不会通过调用 update 来做到这一点。

标签: qt user-interface qgraphicsitem qgraphicsscene


【解决方案1】:
curItem->setTransform(QTransform::fromScale(2.0,2.0), true);

Offtopic:很奇怪,您通过子类化QGraphicsScene 来做到这一点。

【讨论】:

  • 谢谢,我试过了,一切都很顺利。好吧,我是这方面的初学者,所以我将 QGraphicsScene 子类化为使用 scenePos 获取光标的场景坐标
  • 但是这种方法会缩放线条的粗细,我该如何逃避呢?
  • @user3130843 :为避免线条粗细缩放,请使用setCosmetic(true) 笔。看看这个问题stackoverflow.com/questions/17075623/…
  • 为什么每次重新缩放时坐标都会改变,我的意思是新项目的坐标,与旧项目的左上角坐标不匹配?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-08-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-19
  • 1970-01-01
  • 1970-01-01
  • 2016-10-17
相关资源
最近更新 更多