how to disable selection of cells with widgets on qtablewidget
-
wrote on 19 Jan 2023, 22:56 last edited by
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
-
wrote on 20 Jan 2023, 03:04 last edited by
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.
-
wrote on 20 Jan 2023, 09:04 last edited by qwasder85
Set its selection mode to QAbstractItemView::NoSelection.
-
wrote on 20 Jan 2023, 14:40 last edited by JoeCFD
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.
-
wrote on 20 Jan 2023, 17:30 last edited by JoeCFD
@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/5