지금 며칠 동안 문제가 발생했습니다. QTableView를 사용하여 모델의 데이터를 표시하고 있습니다. 사용자가 셀을 클릭 할 때 인터페이스를 사용자에게 친숙하게 만들기 위해 전체 선 선택을 활성화했습니다. self.tableau.selectRow (element.row())QTableView에서 QLineEdit의 최종 버전 신호
그러나 사용자가 F2 키를 누르면 그래서에만 열 편집 1., 예상되는 동작은 다음과 같습니다
- 내가 열 네를 선택한 경우,이 사람은 편집 할 수 없습니다
- 4 열을 선택하면 내가 F2 키를 누르면, 열 (1)는 을 편집 할
그러나 전체 행 선택으로, F2는 어떤 셀이 선택되었는지 알 수 없습니다. 사정은 지금이 라인
def keyPressEvent(self, e):
"""It reimplements event management in this method """
# TODO: find a way to re-select the cell after editing
# We get the name of current file
nom_courant = self.tableau.model().index(self.row_selected, 1).data()
print(nom_courant)
if e.key() == QtCore.Qt.Key_F2:
try:
# We edit the cell name of the selected line
#http://stackoverflow.com/questions/8157688/specifying-an-index-in-qtableview-with-pyqt
self.tableau.edit(self.tableau.model().index(self.row_selected, 1))
except:
print("Pas de cell sélectionnée")
pass
# It retrieves the new file name. CAN NOT do in the
# if the model is not updated yet.
nouveau_nom = self.tableau.model().index(self.row_selected, 1).data()
print(nouveau_nom)
# Call the fct renaming only if the name has changed
if nom_courant != nouveau_nom:
#liste.renameFile(self.current_video, self.tableau.model().index(self.row_selected, 1).data())
print("entropie")
: 그래서, 이벤트 핸들러 다시 구현 내가 생성 한 QLineEdit의 판의 끝을 감지 할 방법이 없습니다
self.tableau.edit(self.tableau.model().index(self.row_selected, 1))
을, 나는 필요 키보드 이벤트가 발생하지 않으면 nouveau_nom이 업데이트되지 않기 때문에 편집 된 셀의 새 내용에 대한 작업을 수행 할 수 있습니다.
엔드 에디션 신호를받는 방법에 대한 아이디어가 있습니까?
(용서해주세요 내 영어, 나는 ... 프랑스어 해요)
답변 해 주셔서 감사합니다. 특히 setSelectionBehavior. 또한 디스플레이가 더 좋습니다. 마지막으로 QLineEdits를 올바르게 처리하기 위해 내 뷰를 서브 클래 싱하고 createEditor를 다시 정의했습니다. returnPressed를 다른 메소드에 연결했습니다. 조언 해 주셔서 감사합니다. 매우 도움이됩니다. – Rififi