How to limit choices in QTableWidget

How do I limit the rows / columns selected in a QTableWidget? I need to force the user to use continuous selection (already done) to select exactly two columns and any number of rows.

Thank!

+5
source share
1 answer

You may have to do one of two things:

  • You will need to subclass QItemSelectionModeland implement functions to add and remove selected QModelIndexes so that you add only two-line elements to it.
  • You can do this by performing a special implementation to catch the signals that it QItemSelectionModelemits, for example:

    connect(tableWidget->selectionModel(), SIGNAL(selectionChanged(QItemSelection &, QItemSelection &)), selectionHandler, SLOT(updateSelection(QItemSelection &, QItemSelection &)));

selectionHandler - , QModelIndex QItemSelection , , , :

selectionHandler->ignoreSelectionUpdateSignal();
tableWidget->selectionModel()->select(QItemSelection&);
selectionHandler->acceptSelectionUpdateSignal();

ignore accept , selectionChanged .

+3

All Articles