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. Select first row in QTableView after selected item is deleted.
Forum Updated to NodeBB v4.3 + New Features

Select first row in QTableView after selected item is deleted.

Scheduled Pinned Locked Moved General and Desktop
7 Posts 4 Posters 11.5k 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.
  • S Offline
    S Offline
    sliver
    wrote on last edited by
    #1

    I have the following problem: I have a TableView with data from a proxy model and as long as the model contains some data element - I want that one element is always selected. So when I delete the selected element for example, I'd like the first element int the TableView to get automatically selected.
    I tried the following options:

    1.:
    @TableView->slectionModel()->setCurrentIndex ( pProxyModel->index(0, 0), QItemSelectionModel::Select | QItemSelectionModel::Rows);@

    1. :
      @TableView->selectRow(0);@

    None of both did work, although the selection mode is QAbstractItemView::SingleSelection and the selection behaviour is QAbstractItemView::SelectRows before the operation.

    Any ideas why this does not work?

    sliver

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      you must

      @
      view->setSelectionBehavior(QAbstractItemView::SelectRows);
      view->setSelectionMode(QTableView::SingleSelection);
      @

      Did you call the first one?

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sliver
        wrote on last edited by
        #3

        no, but the debug output said that this is already the case. These attributes are already set correctly in the ui-File.

        sliver

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goetz
          wrote on last edited by
          #4

          Time to setup a small, complete application so that we can have a look at it.

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0
          • S Offline
            S Offline
            sliver
            wrote on last edited by
            #5

            Unfortunatly this is no solution to me. There is no way to set up a "simple" complete application in a few minutes.
            I looked for someone who maybe had already had the same problem with QItemSelectionModel in Views.
            From further investigation I can say that the line gets selected correctly, but the selection is not painted.

            sliver

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #6

              [quote author="sliver" date="1294997174"]
              From further investigation I can say that the line gets selected correctly, but the selection is not painted.[/quote]
              Now that is interesting! Sounds like a subtle bug.
              Could you tell us at which point you change the selection exactly? In response to what signal or event?

              I am with Volker on this one. I understand that it can be hard to create an example, but it really is the best way to ferret out issues like this. It is sometimes easiest not to rip out your existing code, but to write a small example from scratch. Last time I tried that, my example actually worked, and I managed to find the issue in my main code before posting the example I created. I think something based on QStandardItemModel or the likes might work?

              1 Reply Last reply
              0
              • G Offline
                G Offline
                giesbert
                wrote on last edited by
                #7

                [quote author="sliver" date="1294997174"]Unfortunatly this is no solution to me. There is no way to set up a "simple" complete application in a few minutes.
                I looked for someone who maybe had already had the same problem with QItemSelectionModel in Views.
                From further investigation I can say that the line gets selected correctly, but the selection is not painted.[/quote]

                If the problem only appears in the case you select a line manually, try to create a simple example with a view and a QStandardItemModel. On a button click, select the lines.

                If it's really a bug, it should also appear there, and then you have your simple example.

                Nokia Certified Qt Specialist.
                Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                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