使用 flags() 创建一个 QTableWidgetItem [英] Create a QTableWidgetItem with flags()

查看:58
本文介绍了使用 flags() 创建一个 QTableWidgetItem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白 TableWidgetItem-Chapter 中的 Qt5 文档.我无法获得正确的参数来将我新创建的 TableCell 设置为可编辑.我有这段代码

I dont understand the Qt5 Documentation in the TableWidgetItem-Chapter. I cant get the right parameters to set my freshly created TableCell as editable. I've got this piece of code

for i, item in enumerate(event_desc, start=0):
        print(i, item)
        key   = QTableWidgetItem(list(event_desc)[i])
        value = QTableWidgetItem(event_desc[item])
        value.setFlags( * what's to insert here? * )
        tw.insertRow(i)
        tw.setItem(i, 0, key)
        tw.setItem(i, 1, value)

第一个参数应该是*self,第二个参数是'Union'(这是什么意思?我不能再进一步了,这个参数丢失了)

The first param should be *self, the 2nd one is named 'Union' (What does this mean? i cant go further, this param is missing)

推荐答案

如果您必须将 QTableWidgetItem 设置为可编辑,您必须这样做:

If you must set a QTableWidgetItem as editable you must do:

value.setFlags(value.flags() | QtCore.Qt.ItemIsEditable)

操作符 | 允许启用一个标志,而不是操作 &~ 禁用它们.

The operator | allows to enable a flag, and instead the operation & ~ disables them.

这篇关于使用 flags() 创建一个 QTableWidgetItem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆