以 4.4.3 为例,如果遇到QT本身没有的属性,想要自已添加时,
首先修改 qt\4.4.3\src\gui\text\qtextformat.h
在属性列表里面追加 新的属性
// ADD BEGIN BY Me
UserProperty = 0x100000, //定义属性的独立标识
CGTextUnderline = UserProperty+1
// ADD BEGIN BY Me
然后修改 qt\4.4.3\src\gui\painting\qpaintengine.h
在paint里面追加一个结构体,如表示下划线的结构体,
包含下划线的是否可用,类型、高度、颜色等信息,
(其实下划本身也包含此类的信息,这里有其它的用途。)
// use to draw the text's underline
struct Q_GUI_EXPORT QTextItemUnderlineHint
{
QTextItemUnderlineHint()
: bEnabled(false)
, nPosition(0)
, nHeight(0)
{}
bool bEnabled; // underline enabled
int nStyle; // underline style
int nPosition; // underline position
int nHeight; // underline height
QBrush cBrush; // underline brush
};
Q_DECLARE_METATYPE(QTextItemUnderlineHint);
这样一个下划线的自定义绘制就基本完成了。
剩下的就是在绘制的时候,取得这些信息就可以了。
个人感觉QT的一些限制还是比较多的,
如在QGraphicsTextItem 里面想改变光标的宽度,
还有在本例 字体二 中 ,用鼠标移动文本时,选中文本就会消失,
这些都是偶很头大的问题,
如果大家有什么好的方法,不妨拿出来晒晒。。。