自己实现showTips

ryfdizuo 2010-06-04 02:57:22
我基于QGraphicsRect绘制了一些结点。



如图中,圆角矩形,想实现当鼠标移到圆角矩形的脚点(蓝色或者红色的小矩形)上时,显示一些关于当前脚点的信息。
就像QAction中showTips那样。
能否给个思路。
谢谢~
...全文
274 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
ryfdizuo 2010-06-16
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 tingsking18 的回复:]
这是mouseMoveEvent的解释,设置一下mouseTracking就可以了。
If mouse tracking is switched off, mouse move events only occur if a mouse button is pressed while the mouse is being moved. If mouse tracking is switched o……
[/Quote]

setMouseTracking在scene中没有这个函数的。。。
pywepe 2010-06-08
  • 打赏
  • 举报
回复
厉害 真厉害
ryfdizuo 2010-06-08
  • 打赏
  • 举报
回复
谢谢tingsking18
有时间我试一下~
gemfield 2010-06-06
  • 打赏
  • 举报
回复
mouseTracking关闭即可,学了了,顶楼上
tingsking18 2010-06-06
  • 打赏
  • 举报
回复
这是mouseMoveEvent的解释,设置一下mouseTracking就可以了。
If mouse tracking is switched off, mouse move events only occur if a mouse button is pressed while the mouse is being moved. If mouse tracking is switched on, mouse move events occur even if no mouse button is pressed.
tingsking18 2010-06-05
  • 打赏
  • 举报
回复
跟踪了一下代码,只要重写一下mouseMoveEvent事件,然后调用QToolTip的静态方法ShowText就可以。
QWidget和QGraphicsScene的处理差不多。
void mouseMoveEvent( QMouseEvent* a)
{
QToolTip::showText(a->globalPos(), "hhhhhhhhhhh", this);
};
tingsking18 2010-06-05
  • 打赏
  • 举报
回复
QGraphics中的东西不是继承的QWidget
[Quote=引用 2 楼 qter_wd007 的回复:]

QWidget::setToolTip()
[/Quote]
ryfdizuo 2010-06-05
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 tingsking18 的回复:]
跟踪了一下代码,只要重写一下mouseMoveEvent事件,然后调用QToolTip的静态方法ShowText就可以。
QWidget和QGraphicsScene的处理差不多。
void mouseMoveEvent( QMouseEvent* a)
{
QToolTip::showText(a->globalPos(), "hhhhhhhhhhh", this);
};
[/Quote]
Tips是hoverEnter的时候显示,mouseMove前提是鼠标左/右键被按下,
QGraphicsScene中调用showText,this指针也不能作为QWidget*传值啊~
qter_wd007 2010-06-04
  • 打赏
  • 举报
回复
QWidget::setToolTip()
tingsking18 2010-06-04
  • 打赏
  • 举报
回复
为什么要直接绘制?
参见examples\graphicsview\diagramscene
QGraphicsPolygonItem继承自QGraphicsItem
QGraphicsItem有setToolTip方法,直接使用就可以了啊。

16,213

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧