【问题标题】:PyQt5 converting signal code from PyQt4PyQt5 从 PyQt4 转换信号代码
【发布时间】:2018-02-24 01:48:03
【问题描述】:

我是新手,很难将一行代码从 PyQT4 更改为 PyQT5,这与信号和插槽有关。我怀疑它是因为参数正在传递给插槽。

原行是:

self.connect(self.assetView.selectionModel(), SIGNAL(("currentRowChanged(QModelIndex,QModelIndex)")),self.assetChanged)

我试过了:

self.assetView.selectionModel.currentRowChanged(QModelIndex,QModelIndex).connect(self.assetChanged)

我得到:AttributeError: 'builtin_function_or_method' object has no attribute 'currentRowChanged'

self.assetView 是一个 QTableView 并且 self.assetChanged 有定义:

  def assetChanged(self, index):

感谢任何帮助

【问题讨论】:

    标签: python pyqt pyqt4 pyqt5


    【解决方案1】:

    新语法如下:

    sender.signal.connect(some_slot)
    

    在你的情况下:

    self.assetView.selectionModel().currentRowChanged.connect(self.assetChanged)
    
    #   ^^^^^^^^^sender^^^^^^^^       ^^^^signal^^^^            ^^^^^^slot^^^^^^
    

    def assetChanged(self, current, previous):
        print(current, previous)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-14
      • 2016-05-13
      • 2020-08-03
      • 2021-07-12
      • 1970-01-01
      • 2023-01-23
      • 2014-11-26
      相关资源
      最近更新 更多