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. QTableWidget keeps currentrow to deselected row
Qt 6.11 is out! See what's new in the release blog

QTableWidget keeps currentrow to deselected row

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 2.9k Views 2 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.
  • C Offline
    C Offline
    Crag_Hack
    wrote on last edited by
    #1

    Hi I have a QTableWidget that I select items from. I show information about the currently selected item in the mainwindow widget. However when I deselect an item the current row stays as the row just deselected. What I'd like it to do is change current row to -1 if no row remains selected or change current row to the most recently selected row of the remaining selected rows. Thanks for the help.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      How are you currently connecting this together ?

      Maybe using the selection model would be a better solution.

      Hope it helps

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • C Offline
        C Offline
        Crag_Hack
        wrote on last edited by
        #3

        Here's the code:

        connect(ui->jobsTableWidget,SIGNAL(itemSelectionChanged()),this,SLOT(updateButtons()));
        void ReplicatorMainScreen::updateButtons()
        {
            for (int count = 0; count < ui->jobsTableWidget->rowCount(); count++)
                if (ui->jobsTableWidget->item(count,0)->isSelected())
                    selected = true;
            if (selected == true)
                emit updateJobInfo(ui->jobsTableWidget->currentRow(),0);
        }
        

        I was thinking maybe I could use a stack to keep track of selected rows and change to the previous selected row when necessary... anything easier ideas?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by SGaist
          #4

          Why not use the selection model hasSelection method for that purpose ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • C Offline
            C Offline
            Crag_Hack
            wrote on last edited by
            #5

            Sorry for the delayed response been busy.. can it do what I mentioned in the first post regarding current row being changed to most recently selected row?

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              You have to store the last selected row and re-use it when needed.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              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