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.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.
  • J Offline
    J Offline
    JoeCFD
    wrote on 19 Jan 2023, 22:56 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
    • K Offline
      K Offline
      Kent-Dorfman
      wrote on 20 Jan 2023, 03:04 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.

      I light my way forward with the fires of all the bridges I've burned behind me.

      1 Reply Last reply
      1
      • Q Offline
        Q Offline
        qwasder85
        wrote on 20 Jan 2023, 09:04 last edited by qwasder85
        #3

        Set its selection mode to QAbstractItemView::NoSelection.

        1 Reply Last reply
        0
        • J Offline
          J Offline
          JoeCFD
          wrote on 20 Jan 2023, 14:40 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
          • J Offline
            J Offline
            JoeCFD
            wrote on 20 Jan 2023, 17:30 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

            1/5

            19 Jan 2023, 22:56

            • Login

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