Bonjour,

je souhaiterais, quand la touche TAB est appuyée dans une QTableView, me déplacer vers le bas plutôt que vers la droite comme proposé par défault dans Qt. Pour cela, j'ai intercepté le signal d'une touche appuyée (keyPressEvent) et je détecte si c'est une touche TAB pour appeler ma fonction (searchNextIndex). Elle fonctionne plutôt bien sauf quand il y a des span dans le tableau. Dans ce cas, la case sélectionnée disparaît (l'index n'est pas trouvé à cause du span sur une case voisine). Auriez-vous une idée pour améliorer les choses ? Merci !!

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
31
void customTableView::searchNextIndex() {
    int row = currentIndex().row();
    int col = currentIndex().column();
    // Following cell
    row++;
    if(row>=model()->rowCount()) {
        row = 0;
        col++;
    }
    if(col>=model()->columnCount()) {
        col = 0;
    }
    // Loop while following cell is not selectable (or a complete loop has been done)
    unsigned int counter = 0;
    unsigned int maxCounter = model()->rowCount()*model()->columnCount()-1;
    Qt::ItemFlags currentFlag = model()->flags(model()->index(row, col));
    while(counter<maxCounter && !currentFlag.testFlag(Qt::ItemIsSelectable)) {
        row++;
        if(row>=model()->rowCount()) {
            row = 0;
            col++;
        }
        if(col>=model()->columnCount()) {
            col = 0;
        }
        currentFlag = model()->flags(model()->index(row, col));
        counter++;
    }
    setCurrentIndex(model()->index(row, col));
    scrollTo(model()->index(row, col));
}