2010-06-29 352 views

回答

3

您有幾個不同的選項。最直接的爲你問什麼是使用與該按鈕相關的QHeaderView

// you could also use verticalHeader() 
connect(tableWidget->horizontalHeader(), SIGNAL(sectionClicked(int)), ...); 

另一種選擇是聽selection model

connect(tableWidget->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)), ...) 

但是,此選項將要求您檢查選擇是否僅選擇了整行,除非您的SelectionMode防止它被其他方式阻止。

+0

不確定爲什麼,但它根本沒有發出'SIGNAL(selectionChanged(const QItemSelection&,const QItemSelection&))'信號。相反,使用'SIGNAL(currentChanged(const QModelIndex&,const QModelIndex&))'爲我做了訣竅。 – Claudiu 2017-11-14 17:14:29

0

這是對我工作:

connect(tableWidget->selectionModel(), SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)), ...) 

我上心從here