PyQt5从PyQt4转换信号代码

问题描述:

我是一个新手,并且难以将一行代码从PyQT4更改为PyQT5,它与信号&插槽有关。我怀疑它是因为参数正在传递给插槽。PyQt5从PyQt4转换信号代码

原线为:

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): 

感谢所有帮助

新的语法如下:

sender.signal.connect(some_slot) 

你的情况:

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

# ^^^^^^^^^sender^^^^^^^^  ^^^^signal^^^^   ^^^^^^slot^^^^^^ 

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