Problems with Open-Source Downloads read https://www.qt.io/blog/problem-with-open-source-downloads and https://forum.qt.io/post/638946

[SOLVED] After leaving focus of tableView deselect rows



  • hi, my problem is very simple, when i change tables with TAB, row stays selected in previous tables. i have three tableViews...my app doesnt use mouse. i control it via arrows UP/down, TAB for changing tables and ENTER for activate current row .

    My solution:

    In your window/widget class you must implement eventFilter(QObject *obj, QEvent *event) function from QObject
    and handle the event like this:

    @bool MainWindow::eventFilter(QObject *obj, QEvent *event)
    {
    if (obj == ui->listAlbums) {
    if (event->type() == QEvent::FocusIn) {
    trackSelection->clearSelection();
    return true;
    } else {
    return false;
    }
    }

    if (obj == ui->listTracks) {
        if (event->type() == QEvent::FocusIn) {
            albumSelection->clearSelection();
            return true;
        } else {
            return false;
        }
    }
    
    else {
        // pass the event on to the parent class
        return QMainWindow::eventFilter(obj, event);
    }
    

    }
    @

    listAlbums, listViews are my tableViews



  • You didn't state what exactly is the problem. I think you mean when you change the focus to another table you want the selected row to disappear right?
    Maybe you can use seCurrentCell(-1,-1)

    Also there is "this":http://qt-project.org/forums/viewthread/1195 which may be of use



  • i dont want it dissaper..i need to use "clearSelection()' on the selection of theprevious table, or better, all tables except the one which is focused.



  • Then use clear selection of the other tables in the cellActivated event of all of the tables
    @
    cellActivated(int row, int column) [signal]
    @



  • or similar signals :)



  • Qt has one nice signal "..entered" but it works only for mouse...such a shame :)
    cellActivated works for tableWidget, i have tableViews...

    maybe good idea would be re-implement QEvent http://qt-project.org/doc/qt-4.8/qfocusevent.html

    then i could catch TAB keypress and clearSelection on the others tableViews



  • [quote author="169Martin" date="1403785433"]
    maybe good idea would be re-implement QEvent http://qt-project.org/doc/qt-4.8/qfocusevent.html
    then i could catch TAB keypress and clearSelection on the others tableViews[/quote]

    Yes it seems so :) If you think your problem is solved don't forget to edit the title of the thread and add [SOLVED] to the end of it.



  • thanks for help amahta, i have posted solution , hope its gonna help somebody :)


Log in to reply