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. How to clear the old selected item, when new one is selected
Forum Updated to NodeBB v4.3 + New Features

How to clear the old selected item, when new one is selected

Scheduled Pinned Locked Moved Unsolved General and Desktop
qt5table widget
5 Posts 3 Posters 850 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
    deleted286
    wrote on last edited by
    #1

    I have a function that, give the selected items

    void Widget::on_tableWidget_itemDoubleClicked(QTableWidgetItem *item)
    

    When i change the item, the old item doesnt clear,

    i've tried the below code, but it doesnt let me any item because it clears the selection immediately

    void Widget::on_tableWidget_itemSelectionChanged()
    {
    
    ui->tableWidget->clearSelection();
      
    }
    

    What is the solution of it?

    jsulmJ artwawA 2 Replies Last reply
    0
    • D deleted286

      I have a function that, give the selected items

      void Widget::on_tableWidget_itemDoubleClicked(QTableWidgetItem *item)
      

      When i change the item, the old item doesnt clear,

      i've tried the below code, but it doesnt let me any item because it clears the selection immediately

      void Widget::on_tableWidget_itemSelectionChanged()
      {
      
      ui->tableWidget->clearSelection();
        
      }
      

      What is the solution of it?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @suslucoder said in How to clear the old selected item, when new one is selected:

      What is the solution of it?

      Get selected items using https://doc.qt.io/qt-5/qtablewidget.html#selectedItems, iterate over them and call https://doc.qt.io/qt-5/qtablewidgetitem.html#setSelected on all of them except the item passed to on_tableWidget_itemDoubleClicked.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      D 1 Reply Last reply
      0
      • jsulmJ jsulm

        @suslucoder said in How to clear the old selected item, when new one is selected:

        What is the solution of it?

        Get selected items using https://doc.qt.io/qt-5/qtablewidget.html#selectedItems, iterate over them and call https://doc.qt.io/qt-5/qtablewidgetitem.html#setSelected on all of them except the item passed to on_tableWidget_itemDoubleClicked.

        D Offline
        D Offline
        deleted286
        wrote on last edited by
        #3

        @jsulm im getting selected items in that way

        QList<QTableWidgetItem*> MySelList = ui->tableWidget->selectedItems();
              for (QTableWidgetItem* item : MySelList)
              {
        
                  scln = QString::fromStdU16String(item->text().toStdU16String());
                 qDebug() << scln;
                   
        }
        
        jsulmJ 1 Reply Last reply
        0
        • D deleted286

          @jsulm im getting selected items in that way

          QList<QTableWidgetItem*> MySelList = ui->tableWidget->selectedItems();
                for (QTableWidgetItem* item : MySelList)
                {
          
                    scln = QString::fromStdU16String(item->text().toStdU16String());
                   qDebug() << scln;
                     
          }
          
          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @suslucoder Did you read my post?

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1
          • D deleted286

            I have a function that, give the selected items

            void Widget::on_tableWidget_itemDoubleClicked(QTableWidgetItem *item)
            

            When i change the item, the old item doesnt clear,

            i've tried the below code, but it doesnt let me any item because it clears the selection immediately

            void Widget::on_tableWidget_itemSelectionChanged()
            {
            
            ui->tableWidget->clearSelection();
              
            }
            

            What is the solution of it?

            artwawA Offline
            artwawA Offline
            artwaw
            wrote on last edited by
            #5

            @suslucoder have you tried setSelectionMode(QAbstractItemView::SingleSelection); on your table widget? Seems like you try to implement behaviour that's already there.

            https://doc.qt.io/qt-5/qabstractitemview.html#SelectionMode-enum
            https://doc.qt.io/qt-5/qabstractitemview.html#selectionMode-prop

            For more information please re-read.

            Kind Regards,
            Artur

            1 Reply Last reply
            3

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved