Results 1 to 3 of 3

Thread: Model, view, resize to show all data

  1. #1
    Join Date
    Jan 2006
    Posts
    73
    Thanks
    16
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Model, view, resize to show all data

    Hello,
    The constructor is like this:
    Qt Code:
    1. Test::Test(QWidget* parent)
    2. : QWidget(parent)
    3. {
    4. //Model
    5. QDirModel* model = new QDirModel;
    6. QModelIndex parentIndex = model->index(QDir::currentPath());
    7. //text
    8. text = new QTextEdit;
    9. int row = model->rowCount(parentIndex);
    10. int col = model->columnCount(parentIndex);
    11. for(int i(0); i<row; ++i)
    12. for(int j(0); j<col; ++j)
    13. {
    14. QModelIndex index = model->index(i, j, parentIndex);
    15. text->append(model->data(index, Qt::DisplayRole).toString());
    16. }
    17. //view
    18. view = new QTableView;
    19. view->setModel(model);
    20. view->setRootIndex(parentIndex);
    21. //splitter
    22. splitter = new QSplitter(this);
    23. splitter->addWidget(text);
    24. splitter->addWidget(view);
    25. }
    To copy to clipboard, switch view to plain text mode 
    How can I make sure that the text, view, and splitter will resize automatically to display all the data?
    Many thanks in advance.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Model, view, resize to show all data

    Set a layout for that Test widget or subclass the QSplitter instead of QWidget.

  3. #3
    Join Date
    Jan 2006
    Posts
    73
    Thanks
    16
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Model, view, resize to show all data

    Jacek,
    Thanks; things are starting to look good:

    Qt Code:
    1. Test::Test(QWidget* parent)
    2. : QWidget(parent)
    3. {
    4. QHBoxLayout* mainLayout = new QHBoxLayout(this);
    5. //Model
    6. QDirModel* model = new QDirModel;
    7. QModelIndex parentIndex = model->index(QDir::currentPath());
    8. //text
    9. QTextEdit* text;
    10. text = new QTextEdit;
    11. int row = model->rowCount(parentIndex);
    12. int col = model->columnCount(parentIndex);
    13. for(int i(0); i<row; ++i)
    14. for(int j(0); j<col; ++j)
    15. {
    16. QModelIndex index = model->index(i, j, parentIndex);
    17. text->append(model->data(index, Qt::DisplayRole).toString());
    18. }
    19. //view
    20. view->setModel(model);
    21. view->setRootIndex(parentIndex);
    22. //splitter
    23. QSplitter* splitter = new QSplitter;
    24. mainLayout->addWidget(splitter);
    25. splitter->addWidget(text);
    26. splitter->addWidget(view);
    27. QList<int> list;
    28. list << 1000 << 1000;
    29. splitter->setSizes(list);
    30. }
    To copy to clipboard, switch view to plain text mode 
    But the "text" and "view" boxes of the splitter are of the same size. I would like their sizes to adjust automatically to the amount of data that needs to be displayed so that scroll bars would not be needed. I tried to play with the setSizes function but without luck.

Similar Threads

  1. Default Item View classes and returning data from model
    By xerionn in forum Qt Programming
    Replies: 8
    Last Post: 23rd April 2009, 19:50
  2. Replies: 1
    Last Post: 23rd November 2008, 14:11
  3. Custom Model Advice Requested
    By mclark in forum Qt Programming
    Replies: 3
    Last Post: 18th September 2008, 16:26
  4. Something fishy about Model, data doesn't show up!
    By zlosynus in forum Qt Programming
    Replies: 4
    Last Post: 4th August 2008, 15:07
  5. Model, View and Proxy
    By No-Nonsense in forum Qt Programming
    Replies: 2
    Last Post: 21st November 2006, 08:50

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.