How to use scrollbar in QListView
-
@ QFileInfo fileinfo = QFileInfo(fileName);
model->setRootPath(fileinfo.absoluteDir().absolutePath());
model->setReadOnly(true);ui->listView->setModel(model);
ui->listView->setRootIndex(model->setRootPath(fileinfo.absoluteDir().absolutePath()));
ui->listView->setCurrentIndex(model->index(fileinfo.absoluteFilePath()));
ui->listView->scrollToBottom();
@while i open a file, I want to use QListView to show all the files in this folder, and meanwhile, get the scrollbar scroll tho the file.
But the scrollbar remain in the top when all the files showed. Then, when i open another file in this folder, the scrollbar work well.
I debug to see how scrollToBottom() work, i find when i first open a file, the maximum value of the scrollbar remain ZERO.
Is there any way, when i first load a file, the scrollbar will scroll to the file automatically.
THX :D
-
Hi and welcome to devnet,
To change the folder, you need to call setRooIndex with the appropriate index
-
[quote author="SGaist" date="1407966298"]Hi and welcome to devnet,
To change the folder, you need to call setRooIndex with the appropriate index[/quote]
thx
but I have opened the folder correctly, but the scrollbar doesn't work well, as it doesn't scroll to the correct position, it still remain the top, -
That's strange, what version of Qt are you using ? On what OS ?
-
[quote author="SGaist" date="1408487317"]That's strange, what version of Qt are you using ? On what OS ?[/quote]
Thx, i have solved it recently.This is because when i use
@listView->setModel(model)@
, the model is not set immediately. I just find it by debugging setModel() :D.Then i find this singal of Q***Model
@void layoutChanged();@
this signal can be used here, but i think this is not the best solution. as before the model is completely loaded, the signal is emitted several times. -
Indeed ! Detail I forgot, the QFileSystemModel is threaded