• 9500阅读
  • 3回复

《C++ GUI Qt 4编程》(第2版)第8章原书中的一处自相矛盾 [复制链接]

上一主题 下一主题
离线yysr
 

只看楼主 倒序阅读 楼主  发表于: 2009-04-10
《C++ GUI Qt 4编程》(第2版)第8章中的一处自相矛盾,是原书中的问题。

中文第164~165页中关于Annotion类的定义,在构造函数中使用了
setFlag(ItemIgnoresTransformations, true);

ItemIgnoresTransformations标识设置为true,使得无论场景被如何缩放,传递给该类的paint槽的option的levelOfDetail将始终为1。
文中所述当场景缩小时,不太重要的注解会消失。在这一点上自相矛盾。
事实上场景缩放,注解的显示既不会变大变小,也不会消失。
离线yfx2003

只看该作者 1楼 发表于: 2009-04-29

看来是作者的程序和文述内容矛盾引起的
www.qtcn.org/gpq4/
ajaxref.okajax.com/
离线318065268
只看该作者 2楼 发表于: 2009-06-17
事实上场景缩放,注解的显示既不会变大变小,也不会消失。

我在Qt4.3.5,RedHat 9下编译运行的结果是,缩放场景到一定程度后注解会出现或消失,如同书中所说,有个阈值。
void QGraphicsItem::setFlag ( GraphicsItemFlag flag, bool enabled = true )
If enabled is true, the item flag flag is enabled; otherwise, it is disabled.

QGraphicsItem::ItemIgnoresTransformations
The item ignores inherited transformations (i.e., its position is still relative to its parent, but the parent or view rotation, zoom or shear transformations are ignored). This flag is particularly useful for text label items, which can become unreadable when the view zooms away from the scene. By default, this flag is disabled. This flag was introduced in Qt 4.3.

根据英文文档的说明,setFlag第一个参数表明忽略继承的缩放;而paint槽option的levelOfDetail,应该是由所在场景传递过去的,而非来自自己。项--视图 的思想还需要好好理解。
Email  rsail@126.com(私人邮箱)
QQ:   318065268
离线yysr

只看该作者 3楼 发表于: 2010-02-07
没看懂楼上所说的,我在Windows试,始终出不来书中所说的效果,注解永远不会消失。
快速回复
限100 字节
 
上一个 下一个