×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    1

    Question QTreeView appears un-ordered and without a scrollbar on startup

    Hello,

    I have a problem making QTreeView work as expected.

    I'm trying to make a simple filesystem tree using QFileSystemModel. I made this to work, but when I start my application, in the first 0.5 - 1 seconds of running the program the tree appears un-ordered (beginning with the home folder) and without a scrollbar. Example pictures are as follows:

    This is as it appears on the cold startup for the first 0.5 - 1 seconds:



    This is as it appears after the previous image, that is, after 0.5 - 1 seconds:



    My code is as follows:

    mainwindow.cpp
    Code:
    #include <QtGui>
    
    #include "mainwindow.h"
    
    MainWindow::MainWindow() {
    
        QString startPath = QDir::currentPath();
    
        // create system models ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
        treeModel  = new QFileSystemModel(this);
        treeModel->setFilter(QDir::NoDotAndDotDot | QDir::AllDirs);
        treeModel->setRootPath("/");
    
        // tree ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
        treeDock = new QDockWidget("Tree view", this);
        treeView = new QTreeView(treeDock);
    
        QWidget* dummyWidget = new QWidget(); //remove dock titlebar
        treeDock->setTitleBarWidget(dummyWidget);
    
        treeView->setModel(treeModel);
        treeView->setHeaderHidden(true); //no headers
        treeView->setUniformRowHeights(false); //better performance
        treeView->hideColumn(1);
        treeView->hideColumn(2);
        treeView->hideColumn(3);
        treeView->hideColumn(4);
    
        treeView->setRootIndex(treeModel->index("/"));
        treeView->setCurrentIndex(treeModel->index(startPath));
        treeView->scrollTo(treeModel->index(startPath));
    
        treeDock->setWidget(treeView); //add tree to dock
        this->addDockWidget(Qt::LeftDockWidgetArea, treeDock);
    
        // statusbar ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        status = statusBar();
    
    }
    (I do need the dock)

    mainwindow.h
    Code:
    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    #include <QMainWindow>
    #include <QtCore>
    #include <QtGui>
    
    class MainWindow : public QMainWindow
    {
        Q_OBJECT
    
    public:
        MainWindow();
    
    private:
        QFileSystemModel *treeModel;
        QTreeView *treeView;
        QDockWidget *treeDock;
        QStatusBar *status;
        QMenuBar *menuBar;
    
    };
    
    #endif // MAINWINDOW_H
    main.cpp
    Code:
    #include <QtGui/QApplication>
    #include "mainwindow.h"
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        MainWindow w;
        w.show();
    
        return a.exec();
    }
    => My QTCreator project file: download here

    *

    The problem is, I'm trying to eliminate that interval when the tree is un-ordered and without a scrollbar. I want it to appear like in the second picture from the start.

    I was going nuts trying to solve this but no luck...
    Any help would be greatly appreciated!

  2. #2
    Super Contributor
    Join Date
    Mar 2009
    Posts
    1,024

    Re: QTreeView appears un-ordered and without a scrollbar on startup

    Hi,
    Personally I don't know how to really improve it, in the sense that the process that fills the model scanning the FS nodes needs some time and it's slow because maybe your home folder is rich of files and directories.
    Naive solution would be making your home smaller.
    It's anyway a bit weird you don't have scrollbars on the first picture, since items don't fit in the view...

Similar Threads

  1. QTreeView WordWrap?
    By franklovecchio in forum Qt
    Replies: 0
    Last Post: 2010-12-07, 01:13
  2. Replies: 4
    Last Post: 2010-08-12, 10:42
  3. Background application and on startup?
    By StefanK in forum Mobile Java General
    Replies: 2
    Last Post: 2010-04-12, 06:54
  4. I have also ordered it........and my connection is not slow either....
    By mainul_2001 in forum Bluetooth Technology
    Replies: 0
    Last Post: 2002-09-16, 08:32

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×