Been fiddling a bit more with this, and there seems to be something about this Model/View I don't understand. Below is the mainwindow.cpp from a small testproject I have made. The aim is to display folders from the model in my QListView, and higlight the second row. When the first timer goes off, LightItUp() does just that. When the second timer goes off, LightItUp2() opens the folder I want, but does not highlight any items. Am I not changing folders/indexes the way I'm supposed to?
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QEvent>
#include <QKeyEvent>
#include <QDebug>
#include <QTimer>
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
model = new QFileSystemModel;
model->setRootPath("/Users/anders/Downloads");
list->setModel(model);
list->show();
QTimer::singleShot(3000,
this,
SLOT(LightItUp
()));
}
void MainWindow::LightItUp()
{
qDebug("LightItUp");
list->setRootIndex(model->index(model->rootPath()));
list->setCurrentIndex(model->index(1, 0, list->rootIndex()));
QTimer::singleShot(3000,
this,
SLOT(LightItUp2
()));
}
void MainWindow::LightItUp2()
{
qDebug("LightItUp2");
list->setRootIndex(model->index("/Users/anders/Downloads/Browser"));
list->setCurrentIndex(model->index(1, 0, list->rootIndex()));
}
MainWindow::~MainWindow()
{
delete ui;
}
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QEvent>
#include <QKeyEvent>
#include <QDebug>
#include <QTimer>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
model = new QFileSystemModel;
model->setRootPath("/Users/anders/Downloads");
list = new QListView;
list->setModel(model);
list->show();
QTimer::singleShot(3000, this, SLOT(LightItUp()));
}
void MainWindow::LightItUp()
{
qDebug("LightItUp");
list->setRootIndex(model->index(model->rootPath()));
list->setCurrentIndex(model->index(1, 0, list->rootIndex()));
QTimer::singleShot(3000, this, SLOT(LightItUp2()));
}
void MainWindow::LightItUp2()
{
qDebug("LightItUp2");
list->setRootIndex(model->index("/Users/anders/Downloads/Browser"));
list->setCurrentIndex(model->index(1, 0, list->rootIndex()));
}
MainWindow::~MainWindow()
{
delete ui;
}
To copy to clipboard, switch view to plain text mode
Bookmarks