【问题标题】:table.dataChanged(index, index).connect(someFunction) failstable.dataChanged(index, index).connect(someFunction) 失败
【发布时间】:2015-07-10 06:18:15
【问题描述】:
table = QTableView()
model = QStandardItemModel()
table.setModel(model)
r = table.model().rowCount()
c = table.model().columnCount()
tLeft = table.model().index(0, 0)
bRight = table.model().index(r, c)
table.dataChanged(tLeft, bRight).connect(SomeFunction)

AttributeError: 'NoneType' object has no attribute 'connect'

目标 - 当 QTableView() 中的用户直接更改其中一项时调用 SomeFunction

我做错了什么?我看到 NoneType 对象不能有属性 connect,但为什么它是 NoneType。

请发表评论。我是初学者。 Qt5.

【问题讨论】:

  • 看起来函数table.dataChanged(tLeft, bRight)返回None。应该从table 对象调用connect 方法吗? (这只是猜测,我没用过Qt5)
  • 如果我把它应用到像table.model().dataChanged(tLeft, bRight).connect(SomeFunction)这样的模型上,它会说TypeError: native Qt signal is not callable
  • 您查看文档了吗?你的哪些对象有connect 方法?你见过它工作的例子吗?
  • 进一步阅读:PyQt5 signals and slots。对于 PyQt4 及之前的版本,还有另一种连接信号和插槽的方式,但在 PyQt5 中不再支持。

标签: python qt pyqt qtableview


【解决方案1】:

你应该这样做:

table.model().dataChanged.connect(someFunction)
# or model.dataChanged.connect(someFunction)

不需要精确的论点。插槽应如下所示:

def someFunction(tLeft,bRight):
    #do stuff

【讨论】:

    猜你喜欢
    • 2010-12-28
    • 1970-01-01
    • 2021-01-30
    • 2012-11-18
    • 2020-02-02
    • 1970-01-01
    • 2012-06-27
    • 1970-01-01
    • 2022-11-18
    相关资源
    最近更新 更多