Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    QTreeView::ScrollTo does no scrolling

    General and Desktop
    2
    2
    1439
    Loading More Posts
    • 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
      xalam last edited by

      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 Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        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 Reply Quote 0
        • First post
          Last post