QDeclarativeItem学习笔记

时间:2014-06-04 23:47:17   收藏:0   阅读:511

最近在用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 the QGraphicsItem::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);

QDeclarativeItem学习笔记,布布扣,bubuko.com

评论(0)
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!