Récupérer l'index du zone de texte
Bonsoir,
Voici encore une question :
j'aurai besoin de connaitre l'index du QLinedit actif.
je vous mets un bout de code je cherche à afficher dans l'étiquette l'index de txt actif soit par un click de souris ou par l'activation via la touche Tab
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| import sys
from PySide import QtCore,QtGui
class Feuille(QtGui.QWidget):
def __init__(self):
QtGui.QWidget.__init__(self)
self.txt=[0]*8
for i in range(8):
self.txt[i]=QtGui.QLineEdit(str(i),self)
self.txt[i].cursorPositionChanged.connect(self.affiche)
self.label=QtGui.QLabel('Index',self,alignment=QtCore.Qt.AlignCenter)
grid=QtGui.QGridLayout()
grid.setSpacing (10)
for i in range(8):
grid.addWidget (self.txt[i],i,0)
grid.addWidget (self.label,i+1,0)
self.setLayout (grid)
def affiche(self):
self.label.setText(???)
if __name__ == '__main__':
app = QtGui.QApplication (sys.argv)
root = Feuille()
root.show()
sys.exit(app.exec_()) |
Merci de votre aide