QTableWidget - Select multiple rows.
Hello,
I am looking to select multiple rows in a tablewidget at once, as if the user had Ctrl+clicked or Shift-clicked on the vertical headers.
I have the selection mode set to QAbstractItemView::ExtendedSelection and can perform this operation by clicking.
Using selectRow(int) clears the previous selection. Looking through the source code, selectRow in QTableView calls QTableViewPrivate::selectRow(int, bool).
My guess is that I would have to reimplement QTableView::selectRow() but I'm not quite sure how to do that to get the behaviour I want. I'm working on it in the mean time but if anyone has any suggestions that would be great.
Edit:
I am currently using Python and PyQt4 for most of my development but I am comfortable with C++ as well.
Re: QTableWidget - Select multiple rows.
Hello Everyone,
Turns out I figured out how to do what I want. I don't know if this is the most elegant way to perform this action but it works. I'm just going to put the idea into a method called "selectRows" in my subclassed table.
Turns out my problem was using QItemSelectionModel::Rows instead of QItemSelectionModel::Select.
Code:
#include <QtGui/QApplication>
#include <QtGui/QTableWidget>
#include <QtGui/QAbstractItemView>
int main(int argc, char *argv[])
{
w.selectRow(1);
w.selectRow(3);
w.selectRow(5);
selectionModel->clearSelection();
w.show(); // ideally, upon show rows 2,4 and 6 should appear selected.
// now, all three rows are selected.
w.resize(350,400);
return a.exec();
}
Re: QTableWidget - Select multiple rows.
what about using the designer go to the properties of the QtableWidget
and for selectionbehavior , SelectRows is active.