Qt 二期所需零散知识点汇总

本文详细解析了Qt中的伙伴编辑模式工作原理,阐述了QModelIndex在ModelView架构中的作用,包括索引创建、遍历及有效性管理。同时,对比了view与widget的差异,介绍了movetoThread的意义。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.伙伴编辑模式

当用户激活标签的快捷键时,鼠标/键盘的焦点将会转移到它的伙伴窗口部件上

Qt对象只有QLabel标签对象才可以有伙伴窗口部件,也只有QLable对象具有快捷键时,伙伴关系才有效

2.QModelIndex

这个类用在被被QAbstractItemModel 派生的模型(item models)的索引。这个索引可以被用在item views,delegates,selection models,用这个索引可以定位项(item)在模型的什么位置。

模型可以通过函数QAbstractItemModel::createIndex() 创建一个新的QModelIndex 对象。使用QModelIndex构造函数构造一个无效的模型索引。在模型中,一个索引来表示对应的一个项(item),每个索引都包含有确定对应项的位置的所有信息。通过给定的row和column可以确定一个索引,每个索引可能都包含一个父索引,用row(),column(),parent()这些函数获取相应的信息。模型中的每个顶级项目都是一个没有父索引的,正因为这个原因,parent()将会返回一个无效的索引,这个索引与无参构造函数QModelIndex() 构造的索引是等价的。

如果知道索引引用的是什么模型,用函数model() 返回模型类型

 

const QAbstractItemModel *QModelIndex::model() const;

/*Returns a pointer to the model containing the item that this index refers to.
A const pointer to the model is returned because calls to non-const functions of the model might invalidate the model index and possibly crash your application.*/1234

 

如果检查一个项是否有孩子索引,chiled() 函数可以实现。

QTreeWidgetItem *QTreeWidgetItem::child(int index) const;
/*Returns the item at the given index in the list of the item's children.*/
123

 

遍历索引级别相同的项,可使用sibling()函数

QModelIndex QModelIndex::sibling(int row, int column) const;
/*Returns the sibling(姊妹的意思) at row and column. If there is no sibling at this position, an invalid QModelIndex is returned.*/12

 

注意 
模型索引(Model indexes)应该在用完后,把它及时清除。在调用更改模型的结构或删除项目的模型函数之后,不应该让索引保持有效。如果您需要在一段时间内使用一个模型索引,那么使用QPersistentModelIndex。

 

3.view是什么类型,和widget有什么区别

view时所控件的基类,

关于model/view的知识下面这篇介绍ok

http://blog.youkuaiyun.com/hahajing9/article/details/6090511

view和widget的区别

https://blog.youkuaiyun.com/bzhxuexi/article/details/9922595

 

4.movetoThread是什么意思

下面

http://blog.csdn.NET/chinabinlang/article/details/35988801

 

 

 

 

 

 

 

 

 


 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值