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. QListWidget - Clear currentRow value?

QListWidget - Clear currentRow value?

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 498 Views
  • 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.
  • E Offline
    E Offline
    Elsworth55
    wrote on last edited by
    #1

    I'm using QListWidget::clearSelection() to clear the user's selection, but this doesn't clear the currentRow value. As such, if the user clicks on the same row that was previously selected, it doesn't generate a currentRowChanged() signal.

    I need a way to clear the currentRow, but I can't see a method for doing so. I've tried calling setCurrentRow() with -1 (the default value when no row is selected) but that just causes the program to crash. I've also tried working around the problem by using the itemClicked() signal to get a signal if the same row is re-selected, but having this signal connected seems to change the behaviour of when the currentRowChanged() signal is generated.

    If I could just clear the currentRow that would solve the problem, but I can't find a way of doing so. Is there a way?

    Thanks a lot.

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Since the currentRow() returns the row with the currentIndex (which has nothing to do with selection) you have to call setCurrentIndex(QModelIndex())

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      E 1 Reply Last reply
      2
      • Christian EhrlicherC Christian Ehrlicher

        Since the currentRow() returns the row with the currentIndex (which has nothing to do with selection) you have to call setCurrentIndex(QModelIndex())

        E Offline
        E Offline
        Elsworth55
        wrote on last edited by
        #3

        @Christian-Ehrlicher said in QListWidget - Clear currentRow value?:

        setCurrentIndex(QModelIndex())

        That solved the problem. Thanks a lot.

        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