Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTreeView::ScrollTo does no scrolling
QtWS25 Last Chance

QTreeView::ScrollTo does no scrolling

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    xalam
    wrote on last edited by
    #1

    I am loading file system in QTreeView and than want to select a particular folder and make it visible. My code selects the folder and it expands it as well but it doesn't scroll to it so I have to do all the scrolling myself which gets annoying since I have to do it every time. Here is my code.
    @ExplorerDialog::ExplorerDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::ProgenyFileDialog),
    dirModel( NULL ),
    selectionModel( NULL )
    {
    ui->setupUi(this);

    dirModel = new FileSystemModelEx;
    
    dirModel->setRootPath("c:/");
    
    ui->treeViewFileSystem->setModel( dirModel);
    
    QSettings settings;
    
    QString sourcePath = settings.value(SOURCE_FOLDER, DEFAULT_SOURCE_FOLDER).toString();
    
    QModelIndex folderIndex = dirModel->index( sourcePath );
    
    ui->treeViewFileSystem->expand( folderIndex );
    ui->treeViewFileSystem->scrollTo( folderIndex, QAbstractItemView::PositionAtTop );
    ui->treeViewFileSystem->setColumnWidth(0, 200 );
    ui->treeViewFileSystem->setCurrentIndex( folderIndex );
    
    // set the left/right panes ratio 1:2
    ui->splitter->setSizes( QList<int>() << 100 << 200 );
    
    selectionModel = ui->treeViewFileSystem->selectionModel();
    
    connect(selectionModel, SIGNAL( selectionChanged(const QItemSelection&, const QItemSelection &) ),
            this, SLOT(selectionChanged (const QItemSelection & , const QItemSelection & ) ) );
    

    }@
    What am I doing wrong?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You are doing it too early. QFileSystemModel uses a thread to populate its content so you have to connect a slot to the directoryLoaded signals and do your scroll in there.

      Hope it helps

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved