本文介紹了PyQt5 從 PyQt4 轉換信號代碼的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我是新手,很難將一行代碼從 PyQT4 更改為 PyQT5,這與信號和插槽.我懷疑它是因為參數(shù)正在傳遞給插槽.
I'm a newbie and am having difficulty changing a line of code from PyQT4 to PyQT5, its to do with signals & slots. I suspect its because arguments are being passed to the slot.
原行是:
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' 對象沒有屬性 'currentRowChanged'
self.assetView 是一個 QTableView 并且 self.assetChanged 有定義:
self.assetView is a QTableView and self.assetChanged has def:
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)
這篇關于PyQt5 從 PyQt4 轉換信號代碼的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權益,請聯(lián)系我們刪除處理,感謝您的支持!