PDA

View Full Version : QDialog / QListView problem



harakiri
10th July 2007, 12:58
hi,

i have a problem using a QDialog to hold a QListView. The dialog displays all files in a selected folder. So far, everything works fine, all files are selectable and have a correct status (selected/unselected). The Problem: Pressing control(strg) + a selects all the displayed files. I didn't implement that, so i assume either the QDialog or the QListView accepts this event. Unfortunately, the strg+a - selection selects all items but gives a wrong amout of contained items. if there are 35 items in a folder, strg+a select them all but sets there number to 140 (x4 everytime).
How can i disable the strg+a selection or overwrite it ? is there a solution without subclassing QDialog or QListView (hell of a work for me in both cases due to a huge project...) ?
:confused:



folderDialog = new QDialog;
folderDialog->setWindowModality(Qt::ApplicationModal);
folderDialog->resize(800, 600);
folderDialog->setWindowTitle("Selected Folder");
folderDialogLayout = new QVBoxLayout;

folderModel = new QDirModel;
folderModel->setFilter(QDir::Files);
folderView = new QListView();
folderView->setModel(folderModel);
folderView->setSelectionMode(QAbstractItemView::MultiSelection );
folderDialogLayout->addWidget(folderView);
...
folderDialog->setLayout....

jpn
10th July 2007, 18:31
Yes, Ctrl+A is a shortcut implemented in the view. The problem seems to derive from the fact that a) QDirModel has 4 fixed colums, b) the shortcut makes everything in the model selected. So even if QListView shows only data from the first column of QDirModel, hidden columns count for QItemSelectionModel. One possible solution is to subclass QDirModel and reimplement columnCount():


class DirModel : public QDirModel
{
public:
DirModel(QObject* parent = 0)
: QDirModel(parent) { }

int columnCount(const QModelIndex& parent = QModelIndex()) const
{
return 1;
}
};