类QTableView为setDelegate提供3个接口:
setItemDelegate--为整个QTableView设置委托
setItemDelegateForRow--为给定行设置委托
setItemDelegateForColumn--为给定列设置委托
问题:如果我只想为一个单元格设置委托,我该如何设置
例如,我得到了一个包含两列的Qtableview,第一列设置了一个定制的QCombobox委托,其中包含了项目human和plant。第二列也使用QCombobox委托设置,但可选项取决于第一列的选择。这意味着第二列中的每个单元格可能有不同的委托
例如,如果从组合框委托中选择数据(行=1,列=1)作为人,则单元格(行=1,列=2)有一个组合框委托,其中包含项目标题、主体、手、脚;如果从组合框委托中将数据(行=2,列=1)选作植物,则单元格(行=2,列=2)有一个组合框委托,其项为根、叶、花
有一个类似的问题,但尚未得到回答,Set Delegate for each cell in a QTableView?
至少(据我所知)PyQt5没有直接的解决方案
问题是,所有项目视图类都使用私有(并且从PyQt不可访问)^{} 函数,该函数首先检查行并返回该行的委托(如果存在),然后对列执行相同的操作(如果存在),最后返回默认委托(内置委托或带有泛型属性的委托集)
setItemDelegate()
)因此,如果要确保委托始终首先基于行/列对(然后“退回”到某个依赖行或列的行为),唯一的解决方案是使用唯一的委托,然后根据行/列位置实现相关函数
我想你有一个XY problem。该逻辑与每个单元格的委托无关,而是基于QModelIndex(提供行和列)实现一个逻辑
相关问题 更多 >
编程相关推荐