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] Signal when a QListView selection changes due to keyboard activity?
Forum Updated to NodeBB v4.3 + New Features

[Solved] Signal when a QListView selection changes due to keyboard activity?

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 10.1k 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
    DrTwox
    wrote on last edited by
    #1

    I have a QDialog, created with QT Designer, that looks like so:
    !http://i.imgur.com/1XdmGvT.png()!

    The list of servers on the left is a QListView with a QStringListModel. Mouse clicking an item in the list view updates the form with the information for the selected item by connecting the view’s activated(QModelIndex) signal to a slot function in the dialog.

    However, pressing up or down on the keyboard also changes the selected item, but no signal is emitted, so the form isn't updated to match the selected item. How can this be fixed?

    I'm using Qt5

    1 Reply Last reply
    0
    • Q Offline
      Q Offline
      qxoz
      wrote on last edited by
      #2

      Hi DrTwox!
      For this cases you should use QItemSelectionModel signals.
      @QItemSelectionModel *selectionModel = ui->listView->selectionModel();
      connect(selectionModel,SIGNAL(currentRowChanged(QModelIndex,QModelIndex)),
      this,SLOT(rowChangedSlot(QModelIndex,QModelIndex)));@

      1 Reply Last reply
      1
      • D Offline
        D Offline
        DrTwox
        wrote on last edited by
        #3

        Thanks for the answer qxoz, but I get the following error at runtime when using that code:

        QObject::connect: No such signal QItemSelectionModel::currentRowChanged(QItemSelection,QItemSelection)

        1 Reply Last reply
        0
        • Q Offline
          Q Offline
          qxoz
          wrote on last edited by
          #4

          Strange it should work. Do you write exactly as i show?
          Not currentRowChanged(QItemSelection,QItemSelection) but currentRowChanged(QModelIndex,QModelIndex) ?

          1 Reply Last reply
          0
          • D Offline
            D Offline
            DrTwox
            wrote on last edited by
            #5

            Oops, I did have that wrong! Thanks.

            However, now the runtime can't find the slot function. What should it look like? I have:

            @void ConnectionDialog::rowChangedSlot( const QModelIndex& selected, const QModelIndex& deselected ) {}
            

            @
            ... but at runtime I get

            QObject::connect: No such slot ConnectDialog::rowChangedSlot(QModelIndex,QModelIndex)

            Here's the connect call:

            @connect( serverListView->selectionModel(), SIGNAL( currentRowChanged(QModelIndex,QModelIndex)), this, SLOT( rowChangedSlot(QModelIndex,QModelIndex) ) );@

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

              I forgot to put the slot function under the private slots: section in the header. All is working now. Thank you for the help!

              1 Reply Last reply
              0
              • Q Offline
                Q Offline
                qxoz
                wrote on last edited by
                #7

                Great!
                If it solved please add to the title [Solved].

                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