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 disable selection of cells with widgets on qtablewidget
Forum Updated to NodeBB v4.3 + New Features

how to disable selection of cells with widgets on qtablewidget

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 4.6k 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.
  • JoeCFDJ Offline
    JoeCFDJ Offline
    JoeCFD
    wrote on last edited by
    #1

    I know how to make items unselectable on qtablewidget. I have a customized widget(button) and add it to some cells by calling setCellWidget(row, coln, widget);
    However, clicking it will trigger table selection which I want to avoid. Any way to make these cells unselectable?

    OS: Ubuntu 18 and QT: 5.15.2

    1 Reply Last reply
    0
    • Kent-DorfmanK Offline
      Kent-DorfmanK Offline
      Kent-Dorfman
      wrote on last edited by
      #2

      It's unclear to me exactly what you are asking, but with my limited understanding...maybe implement setEnabled() for your custom widget, and disable the relevant ones.

      If you meet the AI on the road, kill it.

      1 Reply Last reply
      1
      • qwasder85Q Offline
        qwasder85Q Offline
        qwasder85
        wrote on last edited by qwasder85
        #3

        Set its selection mode to QAbstractItemView::NoSelection.

        1 Reply Last reply
        0
        • JoeCFDJ Offline
          JoeCFDJ Offline
          JoeCFD
          wrote on last edited by JoeCFD
          #4

          Thanks for your help, guys.

          My table is defined as

              m_tableWidget->setSelectionMode( QAbstractItemView::MultiSelection );
              m_tableWidget->setSelectionBehavior( QAbstractItemView::SelectRows );
          
              auto button = new MyButton( this );
              m_tableWidget-> setCellWidget(row, coln, button);
          

          the row is selected when button is pressed. What I want is the row is not selected when button is pressed.

          1 Reply Last reply
          0
          • JoeCFDJ Offline
            JoeCFDJ Offline
            JoeCFD
            wrote on last edited by JoeCFD
            #5

            @JoeCFD said in how to disable selection of cells with widgets on qtablewidget:

            auto button = new MyButton( this );
            m_tableWidget-> setCellWidget(row, coln, button);
            

            Adding a new item to the same cell solves the problem. cell widget seems to be laid out on top of the item.

                auto new_item = new QTableWidgetItem;
                new_item->setFlags( column_item->flags() & ~Qt::ItemIsSelectable );
                m_tableWidget->setItem( row, coln, new_item);
                auto button = new MyButton( this );
                m_tableWidget-> setCellWidget(row, coln, button);
            
            1 Reply Last reply
            1

            • Login

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