Solved How to stop color change from white to blue on click of qtable widget ?
-
How to disable touch on q table widget . i want only use it for display data. i want to disable selection on it , disable change color of cell and disable multiple cell selection ?
-
@Qt-embedded-developer
since you need to create a custom widget subclassed from QTableWidget and override a method from it you cant use the designer directly (unless you create a custom plugin for it)
But you can add the widget on runtime into the layout. The layout is defined in the designer. Access the layout via the ui variable and call addWidget() on it. -
-
@raven-worx though i use QAbstractItemView::NoSelection on selection white blue selection color comes how to stop it also
-
i have used below statement but it shows the light blue color on selection . i don't want this light blue color on selection
ui->MAGNETOMETERtable_widget->setSelectionMode(QAbstractItemView::NoSelection);
ui->MAGNETOMETERtable_widget->setEditTriggers(QAbstractItemView::NoEditTriggers); -
@Qt-embedded-developer
ok, i see.
Alternatives are:Via the view:
Subclass your item view and reimplement QAbstractItemView::selectionCommand() and always returnQItemSelectionModel::NoUpdate
in it.Via model:
Create a custom QSortFilterProxyModel subclass and reimplement QSortFilterProxyModel::flags():Qt::ItemFlags NoSelectionModel::flags(const QModelIndex &index) const { return QSortFilterProxyModel::flags(index) & ~Qt::ItemIsSelectable; }
-
@raven-worx said in How to stop color change from white to blue on click of qtable widget ?:
QItemSelectionModel::NoUpdate
can you provide example for
how to subclass qtable widget ?how to reimplement QAbstractItemView::selectionCommand() ?
-
QItemSelectionModel::SelectionFlags NoSelectionTable::selectionCommand(const QModelIndex &, const QEvent *) { return QItemSelectionModel::NoUpdate; }
-
@raven-worx in above function which name I have to replace with ui->table.
I am not getting how to use it with table widget can you tell me where I have to do changes
For example replacing name with my table widget name , what extra thing I need to do
-
@Qt-embedded-developer
since you need to create a custom widget subclassed from QTableWidget and override a method from it you cant use the designer directly (unless you create a custom plugin for it)
But you can add the widget on runtime into the layout. The layout is defined in the designer. Access the layout via the ui variable and call addWidget() on it.