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. QTableView - Not Getting Selection Changed Signal
Forum Updated to NodeBB v4.3 + New Features

QTableView - Not Getting Selection Changed Signal

Scheduled Pinned Locked Moved General and Desktop
11 Posts 3 Posters 16.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.
  • D Offline
    D Offline
    daviddoria
    wrote on last edited by
    #2

    (There indeed is no selectionChanged signal of a QTableView, sorry)
    -Do you really need the QItemSelectionModel? It doesn't sound like you are doing anything that complex. I think you want to connect the selectionChanged model of the VIEW to a slot.-

    -connect(materialsTable,-
    -SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),-
    -dataModel,-
    -SLOT(selectionChangedSlot(const QItemSelection &, const QItemSelection &)));-

    I would also name your materialsTable materialsTableView or something like that - as to not confuse if the 'table' is a 'tableModel' or a 'tableView'.

    1 Reply Last reply
    0
    • J Offline
      J Offline
      jwomble
      wrote on last edited by
      #3

      Does QTableView have a selectionChanged signal? I can't find it in the class reference.

      1 Reply Last reply
      0
      • D Offline
        D Offline
        daviddoria
        wrote on last edited by
        #4

        Yep, it's in the superclass: http://developer.qt.nokia.com/doc/qt-4.8/qabstractitemview.html#signalSection

        I was just complaining about that here :) : http://developer.qt.nokia.com/forums/viewthread/12604/

        1 Reply Last reply
        0
        • J Offline
          J Offline
          jwomble
          wrote on last edited by
          #5

          I see a slot for selectionChanged() in QAbstractItemView, but not a signal.

          1 Reply Last reply
          0
          • D Offline
            D Offline
            daviddoria
            wrote on last edited by
            #6

            Yikes - please ignore everything I've said so far - I was a bit confused (clearly).

            Can you do this - handle the clicked() signal of the view (or the mouseRelease event if you're making bigger selections) and then use the view's selectedIndexes function to get the selection?

            1 Reply Last reply
            0
            • D Offline
              D Offline
              daviddoria
              wrote on last edited by
              #7

              Gah - it is listed under public functions (http://developer.qt.nokia.com/doc/qt-4.8/qlistview.html#memberSection) even though it is protected (it even says protected right in the declaration in the doc!). Sorry, without subclassing the view this method won't do it for you.

              1 Reply Last reply
              0
              • J Offline
                J Offline
                jwomble
                wrote on last edited by
                #8

                As far as I can tell, using the selectionModel is the correct way to do this, I just can't figure out what I'm doing wrong.

                1 Reply Last reply
                0
                • J Offline
                  J Offline
                  jwomble
                  wrote on last edited by
                  #9

                  What's the first thing you should check in QT when signals/slots don't seem to be working correctly? That your class has the Q_OBJECT macro in it. Added this to the APartsTable class definition, and now I'm hitting the breakpoint.

                  When does Friday get here?

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    daviddoria
                    wrote on last edited by
                    #10

                    Here is a compilable example:

                    http://programmingexamples.net/wiki/Qt/ModelView/ItemSelectionModel

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

                      The table implicitly has a selction model, get with <code>tableView->selectionModel()</code>, you don't need to create a new one.

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

                      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