View Full Version : QDirModel
rvb13
1st November 2007, 22:12
Hi,
I am trying to develop a program which uses the QComboBox and a QListBox coupled with QDirModel.
The QCombobox will be listing all the drives and the listbox will be containing the contents of the Drive that I select from the QComboBox.
I am not able to connect them together.
Can someone please help me.
Thanks
jpn
1st November 2007, 22:29
Start by extending QComboBox with a "currentIndexChanged" signal with QModelIndex parameter:
class ComboBox : public QComboBox
{
Q_OBJECT
public:
ComboBox(QWidget* parent = 0) : QComboBox(parent)
{
connect(this, SIGNAL(currentIndexChanged(int)), this, SLOT(emitCurrentIndexChanged(int)));
}
signals:
void currentIndexChanged(const QModelIndex& index);
private slots:
void emitCurrentIndexChanged(int index)
{
emit currentIndexChanged(rootModelIndex().child(index, modelColumn()));
}
};
Then you can just connect ComboBox::currentIndexChanged(QModelIndex) to QAbstractItemView::setRootIndex(QModelIndex) and you're done. :)
int main(int argc, char* argv[])
{
QApplication a(argc, argv);
QDirModel dirModel;
ComboBox comboBox;
comboBox.setModel(&dirModel);
comboBox.show();
QListView listView;
listView.setModel(&dirModel);
listView.show();
a.connect(&comboBox, SIGNAL(currentIndexChanged(QModelIndex)), &listView, SLOT(setRootIndex(QModelIndex)));
return a.exec();
}
rvb13
2nd November 2007, 16:03
Awesome !
Thanks !
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.