Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] After leaving focus of tableView deselect rows
Qt 6.11 is out! See what's new in the release blog

[SOLVED] After leaving focus of tableView deselect rows

Scheduled Pinned Locked Moved General and Desktop
8 Posts 2 Posters 4.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • 1 Offline
    1 Offline
    169Martin
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • A Offline
      A Offline
      amahta
      wrote on last edited by
      #2

      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

      Thou shalt programme
      http://www.amin-ahmadi.com

      1 Reply Last reply
      0
      • 1 Offline
        1 Offline
        169Martin
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          amahta
          wrote on last edited by
          #4

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

          Thou shalt programme
          http://www.amin-ahmadi.com

          1 Reply Last reply
          0
          • A Offline
            A Offline
            amahta
            wrote on last edited by
            #5

            or similar signals :)

            Thou shalt programme
            http://www.amin-ahmadi.com

            1 Reply Last reply
            0
            • 1 Offline
              1 Offline
              169Martin
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              0
              • A Offline
                A Offline
                amahta
                wrote on last edited by
                #7

                [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.

                Thou shalt programme
                http://www.amin-ahmadi.com

                1 Reply Last reply
                0
                • 1 Offline
                  1 Offline
                  169Martin
                  wrote on last edited by
                  #8

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

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved