QDeclarativeItem学习笔记

来源:互联网 发布:妮维雅 防晒 知乎 编辑:程序博客网 时间:2024/05/16 09:07

最近在用QDeclarativeItem的继承来做Qt界面的控件,一开始发现怎么样也没法自动调用paint函数,后来查看了资料,发现如下字句:

You can subclass QDeclarativeItem to provide your own custom visual item that inherits these features. Note that, because it does not draw anything, QDeclarativeItem sets theQGraphicsItem::ItemHasNoContents flag. If you subclass QDeclarativeItem to create a visual item, you will need to unset this flag.


大意就是说,继承QDeclarativeItem来做控件,要先把QGraphicsItem::ItemHasNoContents标志设置成no,不然没法显示控件。

在构造函数中加入setFlag(ItemHasNoContents,false);之后解决。



后来同事和我说,还有鼠标的事件默认也是没有的,可以按照如下方法设置

mousePress,move,release,在构造函数里添加这句
setAcceptedMouseButtons(Qt::LeftButton);

1 0