首页 > 代码库 > QDeclarativeItem学习笔记
QDeclarativeItem学习笔记
最近在用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);
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。