• 4845阅读
  • 8回复

MouseEvent问题? [复制链接]

上一主题 下一主题
离线huangdi_1
 
只看楼主 倒序阅读 楼主  发表于: 2009-09-16


QGraphicsEllipseItem *sun = new    QGraphicsEllipseItem(0,0,20,20);
  sun->setBrush(Qt::red);
  sun->setPen(QPen(Qt::red));

  QGraphicsItemAnimation *animation = new QGraphicsItemAnimation;
  animation->setItem(sun);

  QGraphicsScene *scene = new QGraphicsScene();
scene->addItem(sun);

QGraphicsView *view = new QGraphicsView(scene);
view->show();

画了一个红太阳,如何用鼠标控制能够拖动太阳走呢?
protected:
  void mousePressEvent(QGraphicsSceneMouseEvent *event);
  void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
  void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);


不知道怎么用这几个函数来实现?谢谢各位大虾提示一下啊!
离线dbzhang800

只看该作者 1楼 发表于: 2009-09-16
实现拖动的话,上面的函数都不需要重载
离线20044454
只看该作者 2楼 发表于: 2009-09-16
如果这个部件由三部分组成 部件a ,b ,c 组成,b为a.c之间连线  拖动c, a不变,b与C连接处随C动,改重写哪里?
让我做一个Qt的大牛!!!!
离线huangdi_1
只看该作者 3楼 发表于: 2009-09-16
引用第1楼dbzhang800于2009-09-16 18:41发表的  :
实现拖动的话,上面的函数都不需要重载


实现鼠标拖动,不需要重载这些函数,那有什么别的方法实现呢?可以简单说一下?谢谢!
离线dbzhang800

只看该作者 4楼 发表于: 2009-09-17
void QGraphicsItem::setFlag ( GraphicsItemFlag flag, bool enabled = true )

If enabled is true, the item flag flag is enabled; otherwise, it is disabled.

See also flags() and setFlags().

void QGraphicsItem::setFlags ( GraphicsItemFlags flags )

Sets the item flags to flags. All flags in flags are enabled; all flags not in flags are disabled.

引用第3楼huangdi_1于2009-09-16 20:22发表的  :
实现鼠标拖动,不需要重载这些函数,那有什么别的方法实现呢?可以简单说一下?谢谢!
离线dbzhang800

只看该作者 5楼 发表于: 2009-09-17
引用第2楼20044454于2009-09-16 20:11发表的  :
如果这个部件由三部分组成 部件a ,b ,c 组成,b为a.c之间连线  拖动c, a不变,b与C连接处随C动,改重写哪里?


直接参考

Foundations of Qt Development
第七章
Interacting Using a Custom Item
离线huangdi_1
只看该作者 6楼 发表于: 2009-09-17
引用第4楼dbzhang800于2009-09-17 08:16发表的  :
void QGraphicsItem::setFlag ( GraphicsItemFlag flag, bool enabled = true )
If enabled is true, the item flag flag is enabled; otherwise, it is disabled.
See also flags() and setFlags().
.......


非常感谢 慢慢研究下。
离线20044454
只看该作者 7楼 发表于: 2009-09-17
引用第5楼dbzhang800于2009-09-17 08:19发表的  :
直接参考
Foundations of Qt Development
.......


谢谢了 就是这样的,看demos里面的例子 没看明白
让我做一个Qt的大牛!!!!
离线robertkun

只看该作者 8楼 发表于: 2009-09-17
好热闹,我也来顶一下,
                                              简单的生活使人快乐!
快速回复
限100 字节
 
上一个 下一个